Tuesday, December 30, 2008

LinearLayout in Android (Horizontal, XML)

If you had read our post on Vertical LinearLayout then this one is just the reverse or Horizontal LinearLayout, on the example we interchange the width's value with the height. And change left to bottom and right to top.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal"
>
    <Button android:id="@+id/RecordBtn" 
        android:text="Record"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" />

    <Button android:id="@+id/PlayBtn" 
        android:text="Play" 
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:gravity="top" />

    <Button android:id="@+id/StopBtn" 
        android:text="Stop"
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        android:gravity="bottom" />

    <Button android:id="@+id/PauseBtn" 
        android:text="Pause"
        android:layout_width="wrap_content" 
    android:layout_height="fill_parent" />
</LinearLayout>

Quick Explanation
Same as the Vertical one, there are 4 buttons and the gravity shows you the text alignment in android.

Further reading
LinearLayout in Hello View in Android

Update History
   before 2012: Here is how you can set this as your layout in your java code
   Jan 17, 2012 - Visual Update
Post a Comment