Android getWidth和getMeasuredWidth
1. 在一个类初始化时,即在构造函数当中我们是得不到View的实际大小的。感兴趣的朋友可以试一下,getWidth()和getMeasuredWidth()得到的结果都是0.但是我们可以从onDraw()方法里面的到控件的大小。
2.这两个所得到的结果的单位是像素即pixel。
getWidth(): 得到的是view在父Layout中布局好后的宽度值,如果没有父布局,那么默认的父布局就是整个屏幕。
getMeasuredWidth():先看一下API里面是怎么说的。
The width of this view as measured in the most recent call to measure(). This should be used during measurement and layout calculations only.
得到的是最近一次调用measure()方法测量后得到的是View的宽度,它仅仅用在测量和Layout的计算中。所以此方法得到的是View的内容占据的实际宽度。
总结(正解):
getWidth(): View在设定好布局后整个View的宽度。
getMeasuredWidth(): 对View上的内容进行测量后得到的View内容占据的宽度,前提是你必须在父布局的onLayout()方法或者此View的onDraw()方法里调用measure(0,0);(measure中的参数的值你自己可以定义),否则你得到的结果和getWidth()得到的结果是一样的。
转自:http://blog.csdn.net/wangbofei/article/details/7795430
Android getWidth和getMeasuredWidth的更多相关文章
- Android getWidth和getMeasuredWidth的区别
		
getWidth 得到的事某个View的实际尺寸. getMeasuredWidth 得到的是某个View想要在parent view里面占的大小 相比你也见过这样的解释,听起来这样的解释也是云里雾里 ...
 - android getWidth()和getMeasuredWidth()方法的区别
		
getWidth() Return the width of the your view. Returns The width of your view, in pixels. 源代码: public ...
 - Android -- getWidth()与getMeasuredWidth()
		
getWidth() Return the width of the your view. Returns The width of your view, in pixels. 源代码: public ...
 - Android中View窗口getWidth和getMeasuredWidth的差别
		
今天在研究自己定义listview的下拉刷新的效果.想移植到项目需求中,再看自己定义源代码时发现了一个问题就是getWidth和getMeasuredWidth两个方法有什么差别,求教万能的百度,经调 ...
 - android中getWidth()和getMeasuredWidth()之间的区别
		
先给出一个结论:getMeasuredWidth()获取的是view原始的大小,也就是这个view在XML文件中配置或者是代码中设置的大小.getWidth()获取的是这个view最终显示的大小,这个 ...
 - android中getWidth()和getMeasuredWidth()
		
getMeasuredWidth()获取的是view原始的大小,也就是这个view在XML文件中配置或者是代码中设置的大小.getWidth()获取的是这个view最终显示的大小,这个大小有可能等于原 ...
 - getWidth()和getMeasuredWidth()的区别
		
结论:getMeasuredWidth()获取的是view原始的大小,也就是这个view在XML文件中配置或者是代码中设置的大小.getWidth()获取的是这个view最终显示的大小,这个大小有可能 ...
 - getWidth() 和 getMeasuredWidth()的区别
		
getWidth(): View在设定好布局后整个View的宽度. getMeasuredWidth(): 对View上的内容进行测量后得到的View内容占据的宽度,前提是你必须在父布局的onLa ...
 - 【转】Android中View的绘制过程 onMeasure方法简述 附有自定义View例子
		
Android中View的绘制过程 当Activity获得焦点时,它将被要求绘制自己的布局,Android framework将会处理绘制过程,Activity只需提供它的布局的根节点. 绘制过程从布 ...
 
随机推荐
- SharePoint 2013 文档库“样式”变了
			
有朋友反馈说文档库的样式变了. 经查证,原来有人修改了视图的"样式":库设置—视图—样式,改为默认即可. 另外,如果编辑页面,编辑web部件的属性,在"杂项"勾 ...
 - Mess it up!搞乱代码
			
Mess it up! 作者: Laruence( ) 本文地址: http://www.laruence.com/2009/01/07/656.html 转载请注明出处 恩,这段代码还能再乱点, ...
 - DOM绑定事件
			
addEventListener(event,function,useCapture)event:事件名,比如clickuseCapture布尔值,指定事件是否在捕获或冒泡阶段执行. 可能值: tru ...
 - SQL代码整理
			
--SQL代码整理: create database mingzi--创建数据库go--连接符(可省略)create table biao--创建表( lieming1 int not null,-- ...
 - 怎样使用github
			
https://www.zhihu.com/question/20070065 https://www.shiyanlou.com/courses/868/labs/3163/document 初次尝 ...
 - vue-swiper的使用
			
写博客不是我的爱好,只是人脑毕竟空间只有那么大,有时候会忘了,好记性不如烂笔头,所以通过博客记录点点滴滴,以后可以翻出来看. vue-awesome-swiper官网链接https://www.npm ...
 - github 推送代码
			
一.所有更新一起推送 .git init //初始化本地仓库 . git add . //添加全部文件 .git commit -m 'add all the file' //提交修改 .git st ...
 - unittest常用的断言方法
			
unittest常用的断言方法 #msg:判断不成立时需要反馈的字符串 assertEqual(self, first, second, msg=None) --判断两个参数相等:first == s ...
 - python 全栈开发,Day126(创业故事,软件部需求,内容采集,显示内容图文列表,MongoDB数据导入导出JSON)
			
作业讲解 下载代码: HBuilder APP和flask后端登录 链接:https://pan.baidu.com/s/1eBwd1sVXTNLdHwKRM2-ytg 密码:4pcw 如何打开APP ...
 - bootstrap之排版样式
			
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...