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(); 触发



更多相关文章

  1. address2line 定位 Android(安卓)c++奔溃位置
  2. android中如何获取经纬度?
  3. Android(安卓)简单定制OptionMenu外观
  4. Cocos2d-x android使用onKeyDown监听返回键实现二次返回退出
  5. android service 之startService(...)
  6. Android一行代码 搞定图片太多,太大OOM(内存溢出)
  7. 【android】解决Viewpager设置高度为wrap_content无效的方法
  8. android属性动画最简单使用

随机推荐

  1. 遍历android根目录的简单资源查看器
  2. Android JSON 解析
  3. android 工具类2
  4. Android 图片转成String保存
  5. Android轻量级JSON操作类
  6. Android脑图
  7. android 入门demo 解析xml
  8. Android之SQLLite
  9. android targetSdkVersion / alertdialog
  10. android 上中文排序