public final int getMeasuredHeight ()
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的大小。(轉換為像素值)