LinearLayout aligns all view (TextView, Button and more )
in a single direction, vertically or horizontally. You can specify the layout
direction with the android:orientation attribute.
Code -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
Weight_sum :
Weight Sum is used in
Linear Layout to specify a different -2 weight to child attribute.
android:layout_weight should be equal to weight sum.
Layout_Weight : This attribute specify
that how much space view ( textview or buttn or any other ) should occupy
on the screen.
weight_sum =
layout_weight + layout_weight + layout_weight + ...
weight_sum is
declare inside the parent attribute and layout_weight
is set in child attribute.
Example -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:baselineAligned="true"
android:orientation="horizontal"
android:weightSum="2"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.25"
android:orientation="vertical"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="to" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="subject" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="message" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="send" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:orientation="vertical"
android:background="#C8CCCC"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="to" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="subject" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="message" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="send" />
</LinearLayout>
</LinearLayout>
No comments:
Post a Comment