【问题标题】:How to get the available Screen Height minus Navigation Bar in HoneyComb?如何获得可用的屏幕高度减去 HoneyComb 中的导航栏?
【发布时间】:2011-02-25 11:26:43
【问题描述】:

有没有办法测量底部导航栏的高度(以像素为单位)?

【问题讨论】:

    标签: android android-3.0-honeycomb


    【解决方案1】:

    顺便说一句……对于像我这样偶然发现这个问题并寻找实际数字的人来说,它是 48 像素(至少在摩托罗拉 Xoom 上)。这是基于这个(诚然是粗略的)测试活动的调试输出,结合了一个没有标题栏的主题(例如,@android:style/Theme.NoTitleBar)和一个高度和宽度都设置为“ 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 的三星 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
    

    【讨论】:

      【解决方案2】:

      同时我找到了解决方案。 honycomb 中有一个新的OnLayoutChangeListener 事件,它允许您等待布局完成,然后测量布局的大小而不是屏幕大小。

      【讨论】:

        猜你喜欢
        • 2018-01-20
        • 1970-01-01
        • 2011-10-31
        • 2016-07-30
        • 1970-01-01
        • 1970-01-01
        • 2017-11-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多