首页 > 解决方案 > 特定设备的 Android 布局未显示

问题描述

我为我的两个设备准备了两种不同的布局。首先我用这段代码检查了宽度和高度:

    Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics ();
    display.getMetrics(outMetrics);

    float density  = getResources().getDisplayMetrics().density;
    float dpHeight = outMetrics.heightPixels / density;
    float dpWidth  = outMetrics.widthPixels / density;

它告诉我,第一个设备有360dp width and 592dp height,第二个360dp width and 692dp height。所以我在这样的文件夹layout-w360dp-h592dplayout-w360dp-h692dp.

事实证明,这些设备不使用它们专用的布局。360dp width and 592dp height设备使用默认布局,360dp width and 692dp height设备使用360dp width and 592dp height.

问题出在哪里?先感谢您!

标签: javaandroidandroid-layoutlayout

解决方案


推荐阅读