Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make multi pane layout for Mobile Phone and Tablet

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 646
    Comment on it

    In this example,we will have a layout in which there are two fragments in an activity.

     

    In our mobile phone,we will show only one fragment but in tablets,we will show both fragments simuntanously.

    activity_main.xml (for mobile phone)

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:orientation="vertical">
       <fragment
           android:id="@+id/main_panel"
           class="com.multipaneui.fragment.MainFragment"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
    />
    </RelativeLayout>

     

    Now make another layout folder with name layout-sw600dp and inside that folder,make a layout file with same name(activity_main.xml)

     

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false"
        android:weightSum="1">
        <fragment
            android:id="@+id/side_panel"
            android:layout_weight="0.3"
            class="com.multipaneui.fragment.SideFragment"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />
        <fragment
            android:id="@+id/main_panel"
            class="com.multipaneui.fragment.MainFragment"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="0.7" />
    </LinearLayout>

     

    Simple layout folder is for mobile but layout-sw600dp is for tablets of screen resolution>=600dp.

     

    Now for java file,MainActivity.java

     

    public class MainActivity extends AppCompatActivity {
        private static final String TAG = MainActivity.class.getSimpleName();
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    }

     

    That's it folks.Now u can test your app at mobile and tablet.Have fun:)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: