我建议您将所有相似的文件命名为相同的名称。
充分利用 Android 提供的限定符,例如尺寸或设置宽度限定符。您可能有小屏幕手机的单窗格布局和平板电脑的多窗格布局。为横向提供多窗格布局(您可以将两个现有布局合并为一个)是一个很好的建议。
例如:
res/layout/onepane.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:id="@+id/frag1"
android:layout_height="fill_parent"
android:name="com.example.android.dummyApp"
android:layout_width="match_parent"
android:background="@drawable/bg"/>
</LinearLayout>
res/layout/twopanes.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<fragment android:id="@+id/fragone"
android:layout_height="fill_parent"
android:name="com.example.android.dummyApp"
android:layout_width="400dp"
android:layout_marginRight="10dp"
android:background="@drawable/bg"/>
<fragment android:id="@+id/fragtwo"
android:layout_height="fill_parent"
android:name="com.example.android.dummyApp"
android:layout_width="fill_parent" />
</LinearLayout>
现在所有可能的布局都已定义,只需使用配置限定符将正确的布局映射到每个配置即可。您现在可以使用布局别名技术来做到这一点:
res/values/layouts.xml:
<resources>
<item name="main_layout" type="layout">@layout/onepane</item>
<bool name="has_two_panes">false</bool>
</resources>
res/values-sw600dp-land/layouts.xml:
<resources>
<item name="main_layout" type="layout">@layout/twopanes</item>
<bool name="has_two_panes">true</bool>
</resources>
注意:values 文件夹中两个 xml 文件中的布尔值。
Smallest-width 限定符允许您定位在 dp 中具有特定最小宽度的屏幕。代替大尺寸限定符,使用 sw600dp 指示双窗格布局适用于最小宽度为 600 dp 的屏幕。
另外,另一种解决方案:
如果您打算为不同的屏幕尺寸制作不同的活动,您可以为同一个项目构建多个 apk。您要发布的每个 APK 都应该有一个单独的 Android 项目。
请查看此链接以获取有关多个 APK 的更多信息。
http://developer.android.com/training/multiple-apks/screensize.html