android 理解View中的getWidth和getMeasuredWidth

分析图:

getWidth:View布局的宽度

getMeasuredWidth:View的实际内容宽度

通过一个效果图和布局的不同来理解“View布局的宽度”和“View的实际内容宽度”到底是什么概念,

效果图:

LinearLayout布局layout_width="fill_parent"里面有多个imageview,

getWidth = 800;   我的屏幕宽度是800

getMeasuredWidth = 2226;  LinearLayout的整个内容宽度是2226,向左拉动右边出现白边为止(不包含白边的宽度)

如果内容没有超出屏幕时,有可能getMeasuredWidth 小于 getWidth

 

当我把LinearLayout布局改成layout_width="wrap_content"时

getWidth:View = 2226;

getMeasuredWidth = 2226; 

根据布局不同获取的getWidth也不同,因此恰恰说明getWidth乃是View的布局宽度

 

view.getHeight和view.getMeasuredHeight道理相同。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值