针对不同设备尺寸的不同布局的经典设置:
要求:
布局是:
layout/main.xml
- 单一窗格布局layout/main-dual.xml
- 双窗格布局在values-large/refs.xml
中跟随10“完美无缺:
<item name="main" type="layout">@layout/main-dual</item>
然而,在values-sw600dp/refs.xml
中使用7“不会:
<item name="main" type="layout">@layout/main</item>
我想这是因为我将主要布局引用给自己。引用具有不同名称的main.xml
副本可以正常工作。
refs.xml
中根本没有values-sw600dp
会产生双窗格布局。
onCreate()
中的例外:
android.content.res.Resources$NotFoundException: Resource ID #0x7f0e0000 type #0x1 is not valid
03-14 18:36:45.591: E/AndroidRuntime(2078): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2144)
03-14 18:36:45.591: E/AndroidRuntime(2078): at android.content.res.Resources.getLayout(Resources.java:853)
所以我的问题是如何引用values-xxx/refs.xml
的默认布局?
答案 0 :(得分:1)
我遇到了同样的问题,这就是我放置了我的ref.xml文件的地方。
对于我的大&amp; sw600dp相关文件,我将它们正确放入.../res/values-large
和.../res/values-sw600dp
文件夹中。但是,我放置了默认的.../res/layout
文件夹而不是.../res/values
文件夹。将它移动到正确的目录后,事情按预期工作。
在android studio中,你可以在左上方的组合框中选择Android
,它只会显示与android相关的资源/文件。如果我错了,第一个refs.xml
出现在布局下,另外两个出现在values/refs.xml
下。我确实有这张照片要张贴,但我的声望点还不够高。
答案 1 :(得分:0)
试试这些。
您可以直接在res文件夹中进行布局。
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)