簡體   English   中英

如何在android中創建兩個固定大小的視圖和一個跨越它們的視圖?

[英]how to create two fixed size views and one view spanned between them in android?

我想創建一個屏幕

具有兩個固定大小的區域:一個區域向左對齊,一個區域向右對齊

在它們之間的另一個區域跨越了所有其他區域?

如果我使用屬性fill_parent進行中間視圖,它將捕獲到第三個孩子的所有區域。

layout_weight=0.Xlayout_width=20dp時,有效屬性是什么?

======

我有一個direction orientation= horizontal的linearLayout。

它有一個layout_weight=0.X的孩子,還有layout_width=20dp

什么是有效財產?

如果您具有水平LinearLayout ,並且第一個子級具有固定的寬度(例如, layout_width="20dp" ),第二個子級具有非零的權重(例如, layout_weight="1" ),而第三個子級具有固定的寬度(例如, layout_width="20dp" ),那么您應該使第一個與左側對齊,第三個與右側對齊,第三個填充它們之間的區域。

也可以使用RelativeLayout做到這一點,但我將保留上述內容,因為上述解決方案應該可以正常工作。

將會是這樣的:

<LinearLayout android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="horizontal">

     <View android:id="@+id/view1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"/>

     <View android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_weight="1"/>

     <View android:id="@+id/view3"
           android:layout_width="20dp"
           android:layout_height="wrap_content"
           android:layout_weight="0"/>

</LinearLayout>

您應該使用android:layout_weight

暫無
暫無

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

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