layout_weight屬性圖解
layout_height的作用:
首先按照聲明的尺寸分配,剩餘的空間再按照layout_weight進行分配
一平均分配:
代碼:
<code class="hljs xml"><!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%2D%2D%3E--><linearlayout android:gravity="center" android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="horizontal" xmlns:android="http://schemas.android.com/apk/res/android"> <textview android:background="#e1d611" android:gravity="center" android:layout_height="50dp" android:layout_weight="1" android:layout_width="0dp" android:text="我是老大我是老大我是老大" android:textcolor="#ffffff" android:visibility="gone"> <textview android:background="#09c0f2" android:gravity="center" android:layout_height="50dp" android:layout_weight="1" android:layout_width="0dp" android:text="我是老二" android:textcolor="#ffffff"> <textview android:background="#074bc1" android:gravity="center" android:layout_height="50dp" android:layout_weight="1" android:layout_width="0dp" android:text="我是老三" android:textcolor="#ffffff" android:visibility="gone"></textview></textview></textview></linearlayout></code>二平均且對齊:
在父控制項裡添加代碼:
android:baselineAligned="false"
三單個分配比例:
在父控制項裡添加
android:weightSum="2"
代碼:
<code class="hljs xml"><!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%2D%2D%3E--><linearlayout android:baselinealigned="false" android:gravity="center" android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="horizontal" android:weightsum="2" xmlns:android="http://schemas.android.com/apk/res/android"> <textview android:background="#09c0f2" android:gravity="center" android:layout_height="50dp" android:layout_weight="1" android:layout_width="0dp" android:text="我是老二" android:textcolor="#ffffff"></textview></linearlayout></code>