Android layout、onLayout 一些简要说明

来源:互联网 发布:matlab python 编辑:程序博客网 时间:2024/06/07 02:29

View中:

public void layout(int l,int t,int r,int b) {

     ...

     onLayout

     ...

}

//changed 表示是否有新的位置或尺寸

protected void onLayout(boolean changed,int left,int top,int right,int bottom) {

     //空实现

}


ViewGroup中:

public final void layout(int l,int t,int r,int b) {

     ...

     super.layout(l, t, r, b);

     ...

}

//changed 表示是否有新的位置或尺寸

protected abstract void onLayout(boolean changed, int l,int t, int r,int b);


说明:

1. 自定义一个view时,建议重写onLayout,以设定它的位置。 

   在外部调用时,调用layout(),触发设定位置。


2. 自定义一个viewGroup时,必须且只能重写onLayout。

   需要在设定子view的位置:调用subview.layout(); 触发

0 0
原创粉丝点击