ViewGroup的onLayout l t r b的意思


package com.taiwan.view;



import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;


public class MyViewGroup extends ViewGroup {


private DisplayMetrics displayMetrics;


public MyViewGroup(Context context, AttributeSet attrs) {
super(context, attrs);
displayMetrics = context.getResources().getDisplayMetrics();
}
     @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);
    //super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    System.out.println("onMeasure="+width+"="+height);
    for (int i = 0; i <getChildCount(); i++) {
View childAt = getChildAt(i);
// childAt.measure(MeasureSpec.EXACTLY, MeasureSpec.EXACTLY);
childAt.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
//int measuredWidth = childAt.getMeasuredWidth();
//int measuredHeight = childAt.getMeasuredHeight();
//System.out.println("onMeasure/childAt="+measuredWidth+"="+measuredHeight);
}
    setMeasuredDimension(width, height);
    }
/* (l,t)左上角 距离父类左边  顶部的距离
* (r,b)右下角距离父类左边  顶部的距离
*/
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
System.out.println("onLayout"+l+"/"+t+"/"+r+"/"+b);
int[][] locations=new int[6][4];
//childAt的宽高(296,314)
locations[0]=new int[]{120,188,120+296,188+314};
locations[1]=new int[]{532,88,532+296,88+314};
locations[2]=new int[]{51,642,51+296,642+314};
locations[3]=new int[]{373,432,373+296,432+314};
locations[4]=new int[]{762,448,762+296,448+314};
locations[5]=new int[]{551,739,551+296,739+314};
    for (int i = 0; i <getChildCount(); i++) {
    View childAt = getChildAt(i);
    int left = locations[i][0];
int top = locations[i][1];
int right = locations[i][2];
int bottom = locations[i][3];
childAt.layout(left, top, right, bottom);
}
}


}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值