There are various ways to switch your layouts. Here are the top two:
Suppose in your code, you are going to inflate R.layout.my_layout
.
- Switch directly by adding selectors to layouts
Implement layouts:
res/layout/my_layout.xml
res/layout-land/my_layout.xml
res/layout-w600dp/my_layout.xml
- Switch indirectly by adding selectors to values
Implement layouts:
res/layout/my_layout_narrow.xml
res/layout/my_layout_wide.xml
Implement values:
res/values/layouts.xml
<resources>
<item name="my_layout" type="layout">@layout/my_layout_narrow</item>
</resources>
res/values-land/layouts.xml
<resources>
<item name="my_layout" type="layout">@layout/my_layout_wide</item>
</resources>
res/values-w400dp/layouts.xml
<resources>
<item name="my_layout" type="layout">@layout/my_layout_narrow</item>
</resources>
res/values-w800dp/layouts.xml
<resources>
<item name="my_layout" type="layout">@layout/my_layout_wide</item>
</resources>