更多參考您定義基礎上,屏幕尺寸不同的佈局,那麼你控制你的源代碼片段之間的相互作用。因此,在主/明細情況下,您將擁有一個處理表格的佈局和另一個處理手機的佈局。 Android會根據其大小自動選擇當前設備的佈局文件。要查看示例,請在Eclipse中啓動一個新項目,選擇主/細節,然後它將完全按照所述創建一個簡單的項目。
從http://developer.android.com/guide/practices/tablets-and-handsets.html
根據屏幕大小採取以下時,系統應用不同的main.xml佈局文件:
RES /佈局/ main.xml中的手機:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- "Fragment A" -->
<fragment class="com.example.android.TitlesFragment"
android:id="@+id/list_frag"
android:layout_width="match_parent"
android:layout_height="match_parent"/> </FrameLayout>
適用於平板電腦的res/layout-large/main.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/frags">
<!-- "Fragment A" --> <fragment class="com.example.android.TitlesFragment"
android:id="@+id/list_frag"
android:layout_width="@dimen/titles_size"
android:layout_height="match_parent"/>
<!-- "Fragment B" --> <fragment class="com.example.android.DetailsFragment"
android:id="@+id/details_frag"
android:layout_width="match_parent"
android:layout_height="match_parent" /> </LinearLayout>
是的我明白,但是你所說的是我必須手動檢查當前屏幕大小並加載正確的片段佈局?畢竟,Android已經內置了屏幕尺寸檢測並相應地選擇資源。那麼他們爲什麼不自動選擇正確的片段佈局呢? – AndroidDev
@AndroidDev不,Android會爲你做。對於字符串,在Values文件夾中有String.xml文件,但是,您可以在其中創建值爲lt的文件夾位置Strings.xml,並將所有內容翻譯爲立陶宛語,在這種情況下,Android會自動加載Lithanian String.xml文件檢測立陶宛語系統語言。這與屏幕尺寸和佈局非常相似,但我還沒有那麼做的樂趣。 [在這裏閱讀更多](http://developer.android.com/guide/practices/screens_support.html) – Marius