Android getMeasuredHeight()与getHeight()的区别

Added in  API level 1

Like  getMeasuredHeightAndState() , but only returns the raw width component (that is the result is masked by  MEASURED_SIZE_MASK ).

Returns

  • The raw measured height of this view.

public final int  getHeight   ()

Added in  API level 1

Return the height of your view.

Returns

  • The height of your view, in pixels.

getMeasuredHeight()返回的是原始测量高度,与屏幕无关,getHeight()返回的是在屏幕上显示的高度。实际上在当屏幕可以包裹内容的时候,他们的值是相等的,只有当view超出屏幕后,才能看出他们的区别。当超出屏幕后,getMeasuredHeight()等于getHeight()加上屏幕之外没有显示的高度。

例:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="240dip"
  android:clipToPadding="false"
  android:scrollY="50dip" >

</RelativeLayout>

这里设置它的高度为240dip,超出屏幕50dip。

getMeasuredHeight()获得的就是240dip的大小。(转换为像素值)

getHeight()获得的是240dip - 50dip的大小。(转换为像素值)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值