我正在努力让自己的布局能够通过Android进行自定义和拾取。
我创建了一个测试应用程序,使用这些资源目录:如何让Android根据屏幕尺寸选择不同的布局
- 布局
- 布局大
- 布局正常
- 布局小
- 布局sw600dp
- 布局sw720dp
- layout-w600dp
- layout-w720dp
- 布局XLARGE
他们基本上都含有相同的布局文件,唯一的区别是,一个文本视图只是有布局目录名的内容:
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnTest"
android:text="Layout xxxxx" />
我的问题是,无论我创建的AVD如何,它们都会拾取“正常”布局文件。 下面是AVD的我已经测试过,并在此调试代码的输出:
Configuration config = getResources().getConfiguration();
String sizeName = getSizeName(this);
Log.d(TAG, String.format("screen config smallestScreenWidthDp:%d screenWidthDp:%d densityDpi:%d sizeName: %s" ,
config.smallestScreenWidthDp, config.screenWidthDp, config.densityDpi, sizeName)); //NON-NLS
- 的Nexus 6P,1440x2560,518ppi:
- smallestScreenWidthDp:360 screenWidthDp:360 densityDpi:640 sizeName:正常
- 银河S4迷你, 4.3" 540x960,256ppi:
- smallestScreenWidthDp:360 screenWidthDp:360 densityDpi:240 sizeName:正常
- WIKO果阿,3.5" 小320x480,165 PPI:
- smallestScreenWidthDp:320 screenWidthDp:320 densityDpi:160 sizeName:正常
我在做什么错?
编辑:这不是一个AVD问题,我在物理设备上得到相同的行为;我的应用选择Nexus 6P(1440x2560,518ppi)和Wiko GOA(320x480,165ppi)设备上的Normal布局。
这是我的test project作为参考。
请尝试DisplayMetrics metrics = getResources()。getDisplayMetrics(); –
也命名您的大,正常和小文件夹sw符号。不要将两个命名约定混合在一起 –
@ M.S.P,那我该怎么做? DisplayMetrics.densityDpi返回与我的其他日志输出相同的值。 –