关于onMeasure()方法和onLayout()方法感悟
来源:互联网 发布:校园网网络波动大 编辑:程序博客网 时间:2024/05/17 06:41
<当你在xml布局中,已经设置了大小参数的时候,如果需要canvas画图工具实现显示效果,此时,需要用onMeasure()方法得到java代码中需要的宽高,然后进行绘制,有一个地方我不太明白,就是很多博客上都说需要调用setMeasuredDimension()方法,但是我没有用到这个,我在onLayout()里面设置了位置和大小。附上代码:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// 得到mHeaderViewz的宽、高
if (mHeaderView != null) {
//设置mHeaderView的宽度和高度
measureChild(mHeaderView, widthMeasureSpec, heightMeasureSpec);
mHeaderViewWidth = mHeaderView.getMeasuredWidth();
mHeaderViewHeight = mHeaderView.getMeasuredHeight();
}
}
//onLayout()方法的作用是继承自View,当布局发生改变时调用
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (mHeaderView != null) {
mHeaderView.layout(0, 0, mHeaderViewWidth, mHeaderViewHeight);
configureHeaderView(getFirstVisiblePosition());
//getFirstVisiblePosition()返回显示在屏幕上的第一个元素在适配器中所处的位置。
}
}
另外附上别人的一些研究和分析:
http://blog.csdn.net/az44yao/article/details/8272215
第一次写博客,希望能坚持下来
- 关于onMeasure()方法和onLayout()方法感悟
- ViewGroup之onMeasure方法和onLayout方法
- 关于onMeasure(),onlayout()方法的简单介绍
- 继承ViewGroup:重写onMeasure方法和onLayout方法
- 继承ViewGroup:重写onMeasure方法和onLayout方法
- 继承ViewGroup:重写onMeasure方法和onLayout方法
- 继承ViewGroup:重写onMeasure方法和onLayout方法
- Android 继承ViewGroup必须重写onMeasure方法和onLayout方法
- 通过重写ViewGroup学习onMeasure()和onLayout()方法
- 通过重写ViewGroup学习onMeasure()和onLayout()方法
- 通过重写ViewGroup学习onMeasure()和onLayout()方法
- 通过重写ViewGroup学习onMeasure()和onLayout()方法
- 通过重写ViewGroup学习onMeasure()和onLayout()方法
- 通过重写ViewGroup学习onMeasure()和onLayout()方法
- 通过重写ViewGroup学习onMeasure()和onLayout()方法
- Android中View的绘制过程 onMeasure和onLayout()方法
- 通过重写ViewGroup学习onMeasure()和onLayout()方法
- 自定义控件初学篇——onMeasure()和onLayout()方法
- Oracle 中使用 fetch bulk collect into 批量效率的读取游标数据
- LINK:fatal error LNK1104: cannot open file“***.lib”
- Oracle三种集合数据类型(索引表,嵌套表,VARRAY 数组)的比较-PLSQL—之三
- Android帧缓冲区(Frame Buffer)硬件抽象层(HAL)模块Gralloc的实现原理分析
- NSDate比较
- 关于onMeasure()方法和onLayout()方法感悟
- PL/SQL表(oracle内存表)---table()函数用法
- AIS解析工具
- 微软 Entity Framework 实体框架工具 - LINQPad,LINQ交互式数据库查询工具
- Socket 通信(Linux)
- DXperience Winforms12.2版的中文使用手册
- 自然语言也支持泛型
- 我在互联网创业失败的启思录(十四) –--敢梦想,敢追寻
- .net页面定时刷新的几种简单方式