Posts Tagged ‘orientation’

Linear Layout in Android

November 15th, 2011 by aabhaanjan
This example is for Linear views :
Steps :
Step 1. Create a new android project.
Step 2. Give the project name.
Step 3. Open res/layout/main.xml
There is a root LinearLayout that defines its orientation to be vertical and horizontal.
Step 4. Here is the code :
[xml]
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<LinearLayout
android:orientation=”horizontal”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:layout_weight=”1″>
<TextView
android:text=”column one”
android:gravity=”center_horizontal”
android:background=”#aa0000″
android:layout_width=”wrap_content”
android:layout_height=”fill_parent”
android:layout_weight=”1″/>
<TextView
android:text=” column two”
android:gravity=”center_horizontal”
android:background=”#00aa00″
android:layout_width=”wrap_content”
android:layout_height=”fill_parent”
android:layout_weight=”1″/>
</LinearLayout>
<LinearLayout
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:layout_weight=”1″>
<TextView
android:text=”row one”
android:textSize=”15pt”
android:gravity=”center_vertical”
android:background=”#000000″
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_weight=”1″/>
<TextView
android:text=”row two”
android:textSize=”15pt”
android:gravity=”center_vertical”
android:background=”#aaaaaa”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_weight=”1″/>
</LinearLayout>
</LinearLayout>
[/xml]
Step 5.Run you app. it will look like this :

droid_tool

This example is for Linear views :

Steps :

Step 1. Create a new android project.

Step 2. Give the project name.

Step 3. Open res/layout/main.xml

There is a root LinearLayout that defines its orientation to be vertical and horizontal.

Step 4. Here is the code :

[xml]

<?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”

android:orientation=”vertical”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”>

<LinearLayout

android:orientation=”horizontal”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”

android:layout_weight=”1″>

<TextView

android:text=”column one”

android:gravity=”center_horizontal”

android:background=”#aa0000″

android:layout_width=”wrap_content”

android:layout_height=”fill_parent”

android:layout_weight=”1″/>

<TextView

android:text=” column two”

android:gravity=”center_horizontal”

android:background=”#00aa00″

android:layout_width=”wrap_content”

android:layout_height=”fill_parent”

android:layout_weight=”1″/>

</LinearLayout>

<LinearLayout

android:orientation=”vertical”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”

android:layout_weight=”1″>

<TextView

android:text=”row one”

android:textSize=”15pt”

android:gravity=”center_vertical”

android:background=”#000000″

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

android:layout_weight=”1″/>

<TextView

android:text=”row two”

android:textSize=”15pt”

android:gravity=”center_vertical”

android:background=”#aaaaaa”

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

android:layout_weight=”1″/>

</LinearLayout>

</LinearLayout>

[/xml]

Step 5.Run you app. it will look like this :

LinearView

Tags: , , , , ,