View margin 和padding, getWidth 和getMeasureWidth的区别

本文解释了在用户界面设计中视图的Padding(内边距)和Margin(外边距)的区别,并详细介绍了如何使用getwidth()和getMeasureWidth()来获取视图的实际宽度与计划宽度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Padding is the space inside the border, between the border and the actual view's content. Note that padding goes completely around the content: there is padding on the top, bottom, right and left sides (which can be independent).

Margins are the spaces outside the border, between the border and the other elements next to this view. In the image, the margin is the grey area outside the entire object. Note that, like the padding, the margin goes completely around the content: there are margins on the top, bottom, right, and left sides.

 

 

getwidth() is used to get width of view that has drawn like (view.getwidth() or view.getheight()).getwidth() and getHeight() will only be populated after the Layout Phase, that is after onLayout()has been called.

getMeasureWidth() is used to get width of view that not drawn yet. like getmeasuredwidth() and getmeasureheight(). example : First call measure view.measure(0,0) and then u can use it with getmeasuredwidth() and getmeasureheight().

should not use getwidth/getHeight the values within onMeasure() or getMeasureWidth()/getMeasureWidth(), since those are only the dimensions the View is initially offered or would like to have, not necessarily the ones it actually ends up getting.

 

http://stackoverflow.com/questions/4142090/how-do-you-to-retrieve-dimensions-of-a-view-getheight-and-getwidth-always-r/4406090#4406090

转载于:https://www.cnblogs.com/zhuqiang/archive/2013/03/10/2952797.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值