我有2個文本視圖在佈局中。 第一個是在左邊和右邊 第一個第二個應該有80% 的寬度和第二應該有20%的寬度對齊TextView彼此 - Android
我怎麼能做到嗎?
,我無法找出該選擇哪種佈局:線性佈局或相對佈局
謝謝!
我有2個文本視圖在佈局中。 第一個是在左邊和右邊 第一個第二個應該有80% 的寬度和第二應該有20%的寬度對齊TextView彼此 - Android
我怎麼能做到嗎?
,我無法找出該選擇哪種佈局:線性佈局或相對佈局
謝謝!
可以用戶線性佈局與重量特性80和20
<LinearLayout
android:orientation="horizontal"
android:layout_height="40dp"
android:layout_width="match_parent">
<TextView
android:text="yes"
android:layout_width="0dp"
android:layout_weight="80"
android:layout_height="40dp"
android:id="@+id/textViewOne"
android:textStyle="bold"
android:textSize="17sp"/>
<TextView
android:text="No"
android:layout_width="0dp"
android:layout_weight="20"
android:layout_height="40dp"
android:id="@+id/textViewTwo"
android:textStyle="bold"
android:textSize="17sp" />
</LinearLayout>
謝謝你的工作 –
可以使用的LinearLayout的每個孩子享有weightSum財產和layout_weight。簡單地說:
<LinearLayout
android:orientation="horizontal"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:weight_sum="100">
<TextView
android:layout_width="0dp"
android:layout_weight="80"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="0dp"
android:layout_weight="20"
android:layout_height="wrap_content" />
</LinearLayout>
謝謝你的幫助 –
不客氣。很高興我可以幫助:) @ElieDaher –
使用LinearLayout。它提供了以layout_weight和weightSum屬性的形式指定百分比寬度或高度的工具。
<LinearLayout
android:orientation="horizontal"
android:weightSum="10"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:text="first text view"
android:layout_width="0dp"
android:layout_weight="8"
android:layout_height="wrap_content"
/>
<TextView
android:text="second text view"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
/>
</LinearLayout>
應該工作。這裏的權重總和爲10,分爲權重8和2,即80%和20%。將解決你的問題。
謝謝你的幫助 –
使用'LinearLayout'使用重量來定義視圖你在問什麼 – Pankaj