也許我誤解了layout_weight參數,但爲什麼這樣的事情不工作,我不能得到它...的Android Layout_weight
<?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:orientation="horizontal" android:weightSum="1">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" android:layout_weight="0.3" android:background="@color/apr_blue"/>
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="TextView"
android:background="@color/apr_brightyellow"/>
<TextView
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="TextView"
android:background="@color/apr_yellow"/>
</LinearLayout>
我有一個的LinearLayout內的三個或更多textviews。 我想將它們放在具有百分比寬度的列中。 而這正是它產生:
隨着layout_weight設置好的〜0.3/0.2/0.5
然後我而變化的layout_weight參數只是有點如下:
<?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:orientation="horizontal" android:weightSum="1">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" android:layout_weight="0.3" android:background="@color/apr_blue"/>
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="TextView"
android:background="@color/apr_brightyellow"/>
<TextView
android:id="@+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="TextView"
android:background="@color/apr_yellow"/>
</LinearLayout>
而現在我得到它,因爲我想:
隨着layout_weight設置爲0.3/0.2/0.5
是一個bug或者也許我真的誤會約layout_weight整個事情?
嘗試改變機器人:weightSum = 「1」 到機器人:weightSum = 「1.0」 重量之和應的浮點值。 – Tarun