分析图:
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道理相同。