Linear Layout

Linear Layout is a view group that aligns all children in a single direction, either vertical or horizonatal.

Important Attributes for the Linear Layout:

Attribute
Description
android:id
This is the ID which uniquely identifies the layout.
android:baselineAligned
This must be Boolean value either “true” or “false” and prevents the layout from aligning its children’s baselines.
android:divider
This is drawable to use as a vertical divider between buttons. You can use a color value, in the form of #rgb, #argb, #rrggbb or #aarrggbb
android:gravity
This specifies how an object should position isc content, on both X and Y axis. Possible values are top, bottom, left, right, center, center_horizontal, center_vertical etc.
android:orientation
This specifies the direction of arrangement and you will use “horizontal” for row and “vertical” for column. Default is horizontal.


For example, following is the content of activity_main.xml containing Linear Layout 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>

Run the application, you can see below output:


Now just change the orientation from vertical to horizontal, android:orientation="horizontal" then run your application, you can see below output:

Comments

Popular posts from this blog

SQLiteDatabase (Without SqliteOpenHelper class)

Set current date to Button and Datepicker dialog

MVC Architecture in Android