2

Suppose I have a layout in the main, non-DPI specific layout resource folder, and that layout does an <include> of a sub layout that exists in both the hdpi/mdpi/ldpi folders. Can I expect the final inflated layout to aggregate either the h/m/l-dpi sub layout depending on the device DPI, just as for "full" layouts?

Thanks!

4

1 に答える 1

0

投稿の時点では、投稿の提案をテストする機会がありませんでしたが、その後、そうする機会があり、他の誰もそうしていないので、私自身の質問に答えます.

はい、次のシナリオは期待どおりに機能します (API レベル 8 でテスト済み)。

レイアウト/main.xml:

... <include layout="@layout/included"/> ...

レイアウト/included.xml:

<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="GENERIC included fragment"/>
</merge>

レイアウト-ldpi/included.xml:

<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="LOW-DPI included fragment"/>
</merge>

たとえば、QVGA デバイスでアプリを実行すると、含まれている部分が LDPI ディレクトリから取得されたビューがレンダリングされますが、LDPI 以外のデバイスでは、レイアウト ディレクトリからデフォルトのものが取得されます。

于 2012-11-19T23:48:54.017 に答える