Tuesday, 15 July 2014

Android Linear Layout

Well on this time we are going to see about Linear layout in android xml file. Android xml file is used to provide the UI for the project.Here we are going to the Linear Layout in android.
Linear Layout is a common layout that is used to assign the area in the Android UI.If you want to allocate the particular area for the textView or Button then you can use the LinearLayout.In android it also contain RelativeLayout ,FrameLayout etc.LinearLayout can be assign by Programmically,it contain the android layout width,height etc.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/previewview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
<TextView
                    android:id="@+id/text_view_2"
                    android:layout_width="90dp"
                    android:layout_height="wrap_content" />
<Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView1"
        android:layout_alignRight="@+id/textView1"
        android:layout_marginBottom="25dp"
        android:text="Button" />
        <LinearLayout
            android:id="@+id/logoContainer"
            android:layout_width="20dp"
            android:layout_height="26dp"
            android:layout_gravity="top|left"
            android:layout_margin="2dp"
            android:background="@color/candidate_other" >
            <ImageView
                android:id="@+id/moveToStartArrow"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_marginBottom="2dp"
                android:layout_gravity="center_vertical"
                android:src="@drawable/emmozhi_icon" />
        </LinearLayout>
</LinearLayout>
A LinearLayout contiant the button,textview,imageView etc in android.In the above program we are imported the xml verdsion package and we created the id for the android LinearLayout.the id is used to call the LinearLayout on the java file(for example human have name)so these id is used to identify the LinearLayout.
And we can also set the layout height and width of the LinearLayout by using width and height.When we are using height and weight we need to give the value by manually or automatically. LinearLayout width and height contain three values such as fill_parent,match_parent,wrap_content.
Fill_parent and match_parent optimizes full line of the LinearLayout and wrap_content take the exact size of the layout.If you want to manually enter the value you need type “30dp” to the width and height.
LinearLayout contain the orientation to place the text,image and button in android.Orientation is of two types they are vertical and horizontal.
You can also create the nested LinearLayout,it contain various function to align the layout by your wish like marginTop,left,bottom and Right.You can also set the background image for your layout.These are the various function of Linear Layout I hope you got some ideas about Linear Layout.

No comments:

Post a Comment