Introduction of Android Linear Layout
Every android control is put in predefined layout. layout provides to arrange android controls. linear layout is mostly used to define application gui. In this we provide orientation of layout.
How to define linear layout
Android use seperate file for layout. This file stored in android res/layout directory.
syntex :
How to define linear layout
Android use seperate file for layout. This file stored in android res/layout directory.
syntex :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout/>
Above syntex define following properties
- android:layout_width this property is used to define width.
- android:layout_height this property is used to define height.
- android:orientation this property is used to define orientation of layout(horizontal or vertical)
Example
- Make layout file(main.xml) which contains two buttons in vertical.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 2" /> </LinearLayout> - Output :

No comments:
Post a Comment