Android(安卓)layout、onLayout 一些简要说明
16lz
2021-01-24
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 abstractvoid onLayout(boolean changed,int l,int t, int r,int b);
说明:
1. 自定义一个view时,建议重写onLayout,以设定它的位置。
在外部调用时,调用layout(),触发设定位置。
2. 自定义一个viewGroup时,必须且只能重写onLayout。
需要在设定子view的位置:调用subview.layout(); 触发
更多相关文章
- address2line 定位 Android(安卓)c++奔溃位置
- android中如何获取经纬度?
- Android(安卓)简单定制OptionMenu外观
- Cocos2d-x android使用onKeyDown监听返回键实现二次返回退出
- android service 之startService(...)
- Android一行代码 搞定图片太多,太大OOM(内存溢出)
- 【android】解决Viewpager设置高度为wrap_content无效的方法
- android属性动画最简单使用