您的位置:首页 > 移动开发 > Android开发

Android layout、onLayout 一些简要说明(转)

2015-11-05 13:41 471 查看
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(); 触发
http://blog.csdn.net/jjwwmlp456/article/details/43983265
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: