我是Android開發新手,我有一個關於在線性佈局中設置重量的問題。Android佈局重量
我想創建一個具有兩個自定義按鈕和自定義編輯文本的行。編輯文本應該只佔用與內容相同的空間,並且這兩個按鈕應該水平擴展以填充行中剩餘的可用空間。像這樣...
| [#Button++#] [#Button--#] [et] |
多次嘗試後,這是最接近我能得到我想要的東西,即使它似乎過於複雜。
| [Button] [Button] [###ET###] |
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:layout_weight="1"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
>
<RelativeLayout
android:id="@+id/btn_plus_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/btn_plus"
android:background="@drawable/btn"
android:layout_centerInParent="true"
></ImageButton>
<TextView
android:textColor="#FAFAF4"
android:id="@+id/tv_dice_plus"
android:text="@string/tv_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
></TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
>
<RelativeLayout
android:id="@+id/btn_minus_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/btn_minus"
android:background="@drawable/btn"
android:layout_centerInParent="true"
></ImageButton>
<TextView
android:textColor="#FAFAF4"
android:id="@+id/btn_minus"
android:text="@string/tv_minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
></TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
>
<EditText
android:textColor="#FAFAF4"
android:text="@string/et_output"
android:id="@+id/et_output"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:selectAllOnFocus="true"
android:minWidth="50sp"
android:maxWidth="50sp"
android:background="@drawable/tv_black_background3"
android:textColorHighlight="#c30505"
></EditText>
</LinearLayout>
</LinearLayout>
據我所知的設置[機器人:layout_weight =「2」]用於保持按鈕線性佈局應使得它們佔用比編輯文本更多的空間,但它確實對置對我來說,使他們都成爲一半。
| [Btn] [Btn] [#####et#####] |
我已經嘗試過很多不同的組合,我什至不記得他們,也沒有工作。
設置的線性佈局的寬度以0dip的工作就像我想要的。我不知道這是一個選擇。這是有道理的,爲什麼這將工作在wrap_content不行的地方。在沒有內容的情況下將寬度設置爲wrap_content會使其消失,但將其設置爲0dip可以使其從無到有,但需要大。非常感謝你。 – UnluckyDevil 2011-02-15 07:01:03