Translate this page to

Search Android

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

Tuesday, December 30, 2008

LinearLayout in Android (Vertical, XML)

Reading this, you probably have a clue that LinearLayout lays out object linearly and can only have a vertical and horizontal layout, no diagonal layout.

Here is an example of a vertical LinearLayout:
(update: horizontal LinearLayout here)
<?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="vertical"
>

  <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_height="wrap_content"
    android:gravity="right"
    android:layout_width="fill_parent">
  </Button>

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

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

</LinearLayout>


Quick Explanation:
There would be 4 buttons here, Record, Play, Stop and Pause, each one have its id and a wrap_content height, 3 of the buttons have fill_parent which mean fill up all spaces their width, gravity is text-align in css. See the picture below to better understand.

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

vertical-linearlayout

0 comments: