Translate this page to

Search Android

Search For Android Tutorials (NEW, Custom Search for Android Developers)
Loading

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>

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

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

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

</LinearLayout>



Quick Explanation
Same as the Vertical one, there are 4 buttons and the gravity shows you the text alignment in android. The picture below would explain it.

Update: Here is how you can set this as your layout in your java code

horizontal-linearlayout

0 comments: