自定义ViewGroup中不能正确显示 其它的viewGroup问题描述:小弟写了一个MyViewGroup(extends ViewGroup),在
自定义ViewGroup中不能正确显示 其它的viewGroup
问题描述:
小弟写了一个MyViewGroup(extends ViewGroup),在MyViewGroup中可以正确显示child view都是widget类型的(例如Button,ImageButton),但不能正确显示其它的ViewGroup比如系统的RelativeLayout。我在xml中RelativeLayout里面只定义了一个ImageButton ,这个ImageButton能够显示出来但显示的位置与xml中定义的不同。
测试类 testViewClass.java :
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
[解决办法]关注,帮顶
[解决办法]我也碰到这个问题啊,只能显示VIEW
[解决办法]@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final int count = getChildCount();
for (int i = 0; i < count; i++) {
getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);
}
}
填上这个就可以了
[解决办法]//心中疑惑:我认为我只要在这里调用child的layout(int,int,int,int)方法给出它的位置和宽高就可以了
//如果child本身是一个ViewGroup的话它是否应该自己去管理它本身内部的child的位置和宽度呢???
同样疑惑。。。求高手解答。。遇到同样问题了~~~
[解决办法]我也遇到这样的问题!