xml中不能直接添加ViewGroup吗

Android 码拜 9年前 (2015-04-27) 1042次浏览 0个评论
 

我知道可以直接添加一个<View />的,今天想添加个容器类,然后后台动态添加SurfaceView到ViewGroup容器里,不过提示inflate报错了。难道ViewGroup不能直接这么添加吗?

<LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >   
	     <ViewGroup
	         android:layout_width="wrap_content"
	         android:layout_height="wrap_content"
	         />	    	    
	</LinearLayout>
xml中不能直接添加ViewGroup吗
40分
不能, ViewGroup 是一个抽象类,无法直接实例化
xml中不能直接添加ViewGroup吗
引用 2 楼 kifile 的回复:

不能, ViewGroup 是一个抽象类,无法直接实例化

那如何我想在xml中定义一个容器,然后activity中,查找这个容器实例,用它的addView()去添加view的话,应该用哪个来实现这个呢?

xml中不能直接添加ViewGroup吗
FrameLayout,或者 LinearLayout, 主要是想看你的用处
xml中不能直接添加ViewGroup吗
引用 4 楼 kifile 的回复:

FrameLayout,或者 LinearLayout, 主要是想看你的用处

纯当一个容器,里面就添加一个SurfaceView。原本是打算每一个容器里添加一个SurfaceView。
如果用Layout的话,一个Layout里把两个SurfaceView都添加进去算了。
谢谢,没api文档,忽略了ViewGroup是抽象类了


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明xml中不能直接添加ViewGroup吗
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!