Display layout of linerlayout by %


If we want to display components of LinearLayout by %.we neet to set android:layout:widh:"0dp".if the orientation is vertical,we need to set android:layout_height="0dp".under this circumstance ,one of components's space scale is itself weight/sum of all the components weight in the LinearLayout.

let me see the demo:

<LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
         >
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:background="#aa0000"
                    android:gravity="center"
                    android:text="1"/>
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="2"
                    android:background="#00aa00"
                    android:gravity="center"
                    android:text="1"/>
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_weight="3"
                    android:background="#0000aa"
                    android:gravity="center"
                    android:text="1"/>
    </LinearLayout>

the effect is:

Display layout of linerlayout by %_第1张图片

你可能感兴趣的:(Display layout of linerlayout by %)