簡體   English   中英

如果有2個按鈕(其中1個具有特殊寬度),如何設置按鈕的寬度以固定線性布局中的其余屏幕尺寸

[英]How to set a Button's width to fix the remaining screen size inside a Linear Layout if there are 2 Buttons (1 with spcified width)

我有一個水平LinearLayout含有2個Buttons ,一個按鈕具有指定的寬度(57dp),另一個應填充剩余的屏幕尺寸。 我這樣嘗試過:

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="37dp"
        android:orientation="horizontal"
        android:layout_marginTop="10dp"
        android:gravity="center_vertical|center_horizontal" >

        <Button
            android:id="@+id/fold_action"
            android:layout_width="fill_parent"
            android:layout_height="34dp"
            android:padding="8dp"
            android:background="@drawable/order_button"
            android:text="test" />
        <Button
            android:id="@+id/like_action"
            android:layout_width="57dp"
            android:layout_height="37dp"
            android:background="@drawable/wish_off" />

    </LinearLayout>

但是通過這種方式,應該填充屏幕其余部分的Button的寬度與LinearLayout相同,因此Buttons離開了屏幕。 有沒有辦法在xml中做到這一點?

將layout_width設置為0dp並將layout_weight設置為1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM