2013-07-29 53 views
0

我想創建一個屏幕如何在android中創建兩個固定大小的視圖和它們之間的一個視圖?

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

,並在它們之間橫跨區域的所有其餘的另一個領域?

如果我用屬性fill_parent作中間視圖,它會將所有區域都抓到第三個孩子。

layout_weight=0.Xlayout_width=20dp時,什麼將會是有效的財產。

======

我有一個orientation= horizontal LinearLayout中。

它有一個孩子layout_weight=0.Xlayout_width=20dp

什麼將是有效的財產?

回答

1

如果具有水平LinearLayout與具有固定的寬度(例如layout_width="20dp")的第一個子,具有非零權重的第二子(例如layout_weight="1")和第三帶一個固定的寬度(例如layout_width="20dp"),則應該將第一個對齊到左邊,第三個對齊到右邊,第三個填充它們之間的區域。

也可以使用RelativeLayout來做到這一點,但我會留下,因爲上述解決方案應該工作得很好。

0

這將是這樣的:

<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

+0

'android:layout_weight =「1」'不會將第三個視圖推出可見區域? –

+0

設置'android:layout_weight =「1」'會使視圖伸縮,而= 0會使它不被拉伸。在這種情況下,您希望View2具有可伸縮性,因此它將放棄View3的一些空間,該空間不會拉伸。 [Here](http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#weight)是文檔。 – Wenhui

相關問題