Android is not choosing the correct layout file

2019-09-08 19:04发布

问题:

I have 3 different layout files

layout/
    main.xml
layout-large/
    main.xml
layout-sw600dp/
    main.xml

My nexus 7 is always using the layout/main.xml

Is there something I have to do to get it to use the layout-sw600dp/main.xml file?

回答1:

The docs didn't mention it but you have to have the supports-screens set up right in AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.gpsinsight.gpsandroid"                                                             
      android:versionCode="1"
      android:versionName="1.0">
    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"        android:largeScreens="true"
        android:xlargeScreens="true" />
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <activity android:name="MainActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>