在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java  Android/ 自定義 View 設(shè)置為全屏?xí)r的高度比 DisplayMetrics 獲得的高度

自定義 View 設(shè)置為全屏?xí)r的高度比 DisplayMetrics 獲得的高度大

通過使用代碼:

DisplayMetrics dm = getResources().getDisplayMetrics();
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;

Log.e(TAG, "W = " + dm.widthPixels + ", H = " + dm.heightPixels);

獲得到屏幕的寬和高,在我測試的手機(jī)上,screenWidth = 1440,screenHeight = 2400
屏幕寬高


然后,自定義 View,設(shè)置 layout_widthlayout_height 都是 match_parent

android:layout_width="match_parent"
android:layout_height="match_parent"

onDraw 方法里面,輸出該 View 的 width 和 height:

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    W = this.getWidth();
    H = this.getHeight();

    Log.e("RegionSelectorView", "W: " + W + ", H: " + H);
}

發(fā)現(xiàn)的輸出都是:
onDraw 的 Log 輸出

請問大家這是為什么,該如何解決這個不一致的問題?

回答
編輯回答
祈歡

沒記錯的話,第一個方法不包含狀態(tài)欄高度

2017年7月12日 06:11