Categories

Archives

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”
[...]

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>