[Solved] How to handle 2 different layouts in an activity Android


I would suggest you to name all similar files with the same name.

Take full advantage of the qualifiers provided by Android like the size, or the set width qualifier. You may have a single pane layout for small screen phones and multi pane layout for tablets. It’s a good advice to provide multi pane layout ( you may combine two existing layouts into one ) for landscape orientation.

For example :

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>

Now that all possible layouts are defined, it’s just a matter of mapping the correct layout to each configuration using the configuration qualifiers. You can now do it using the layout alias technique:

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>

Note : The bool values in the two xml files in values folder.

The Smallest-width qualifier allows you to target screens that have a certain minimum width given in dp. Instead of the large size qualifier, use sw600dp to indicate the two-pane layout is for screens on which the smallest-width is 600 dp.

Also, another solution:

If you are planning to make different activities for different screen sizes, you can build multiple apk for the same project. There should be a separate Android project for each APK you’re going to release.

Please look at this link for more information on Multiple APKs.
http://developer.android.com/training/multiple-apks/screensize.html

2

solved How to handle 2 different layouts in an activity Android