Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • New Layout Features

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 277
    Comment on it

    Hello people,

    With the new roll of android studio 1.4 we have received many cool features one of them is Branching of layout into precise manner.

    Android has introduced two different layouts while we create the main activity, these two activities are merged in one by including the another in first. By default they are named as

     *  activity_main
    
     * content_main
    

    activity_main

    is meant to put all the stuff that are like navigation drawer, floating buttons etc, here we can define the properties that activity will look alike.

    content_main

    is meant to put all the XML views buttons, edit text and all the stuff that will be use for io purpose to the user.

    following is an example of main_activity xml

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:fitsSystemWindows="true" tools:openDrawer="start">
    
        <include layout="@layout/app_bar_main" android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
        <android.support.design.widget.NavigationView android:id="@+id/nav_view"
            android:layout_width="wrap_content" android:layout_height="match_parent"
            android:layout_gravity="start" android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />
    
    </android.support.v4.widget.DrawerLayout>
    

    and following is the content_main XML view for the ui elements that will be used for io

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
        android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:showIn="@layout/app_bar_main"
        tools:context=".MainActivity">
    
        <TextView android:text="Hello World!" android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </RelativeLayout>
    

    Do not forget to include the content_main xml into the activity_main xml like,

    <include layout="@layout/app_bar_main" android:layout_width="match_parent"
                android:layout_height="match_parent" />
    

    Happy coding :)

 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: