我試圖在設置3個着色區域1:2:3的比例使用的TextView:爲什麼View中的layout_weight的效果與TextView的行爲不同?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:background="#FF0000"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
<TextView
android:layout_weight="2"
android:background="#00FF00"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
<TextView
android:layout_weight="3"
android:background="#0000FF"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
</LinearLayout>
具有我的期望結果(屏幕由機器人工作室預覽拍攝):
但當我將TextView更改爲視圖時:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<View
android:layout_weight="1"
android:background="#FF0000"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
<View
android:layout_weight="2"
android:background="#00FF00"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
<View
android:layout_weight="3"
android:background="#0000FF"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
</LinearLayout>
佈局更改(android studio預覽屏幕截圖):
是什麼原因?
問題解決了? –