自定义Viewgroup
1.创建一个JAVA类继承于viewGroup
2.重写构造器
3.复写onLayout方法
4.在onMeasure方法下让子View测量自己
measureChildren(width,height);//让在这个View下的子View自己测量自己(第一个参数是这个View的所要求的宽,第二个参数是这个View所要求的长度)
5.最后得到子View,然后对其布局进行处理
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
View child1=getChildAt(0);
View child2=getChildAt(1);
View child3=getChildAt(2);
View child4=getChildAt(3);
if (child1!=null){
child1.layout(0,0,child1.getMeasuredWidth(),child1.getMeasuredHeight());
}
if (child2!=null){
child2.layout(r-child2.getMeasuredWidth(),0,r,child2.getMeasuredHeight());
}
if (child3!=null){
child3.layout(0,b-child3.getMeasuredHeight(),child3.getMeasuredWidth(),b);
}
if (child4!=null){
child4.layout(r - child4.getMeasuredWidth(), b - child4.getMeasuredHeight(),r,b);
}
}