簡體   English   中英

如何在HoneyComb中獲取可用的屏幕高度減去導航欄?

[英]How to get the available Screen Height minus Navigation Bar in HoneyComb?

有沒有辦法測量底部導航欄的高度(以像素為單位)?

順便說一下......對於像我這樣偶然發現這個問題尋找實際數字的人來說,這是48像素(至少在Motorola Xoom上)。 這是基於此(通常是粗略的)測試活動的調試輸出,結合沒有標題欄的主題(例如,@ android:style / Theme.NoTitleBar)和單一視圖LinearLayout,其高度和寬度都設置為“ match_parent“(例如,創建新Android應用時創建的那個):

package com.sample.layouttest;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnLayoutChangeListener;

public class Main extends Activity implements OnLayoutChangeListener {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View newView = getLayoutInflater().inflate(R.layout.main, null);
    newView.addOnLayoutChangeListener(this);
    setContentView(newView);
    }

    @Override
    public void onLayoutChange(View view, int left, int top, int right,
            int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
        Log.d("LayoutTest","left="+left+", top="+top+", right="+right+", bottom="+bottom);
    }
}

在運行Android 3.1的Motorola Xoom(以及運行3.0的Samsung Galaxy 10.1V)上,進入縱向模式時onLayoutChange方法的輸出為:

05-24 15:11:43.047: DEBUG/LayoutTest(8658): left=0, top=0, right=800, bottom=1232

進入景觀時:

05-24 15:13:18.837: DEBUG/LayoutTest(8658): left=0, top=0, right=1280, bottom=752

同時我找到了解決方案。 在honycomb中有一個新的OnLayoutChangeListener事件,它允許您等待布局完成,然后測量布局的大小而不是屏幕大小。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM