2014-02-12 58 views
0

在我的表單上我有一個標籤,一個多行文本框和一些按鈕。我希望將按鈕對齊到活動底部,多行文本框填充剩餘空間。填充剩餘空間,但也有按鈕對齊底部

我可以讓按鈕捕捉到底部的唯一方法是在容器上使用android:layout_alignParentBottom,這意味着主佈局必須是Relative。

但是,我可以通過多行文本框填充空間的唯一方法是容器是線性佈局,並使用0dp/weight = 1。

底部的包含只是一個帶按鈕的水平線性佈局。

有沒有辦法做到這一點?如下所示,我嘗試過使用Table Rows等。下面是它現在的樣子。

enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    style="@style/fragmentBackdropPlain" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/buttonText" 
      android:text="@string/subtopic_content_name" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 
     <TableRow android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_height="wrap_content"></TableRow> 

     <EditText 
      android:id="@+id/editSubTopicContent" 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent" 
      android:hint="@string/subtopic_content_hint" 
      android:inputType="textMultiLine" > 

      <requestFocus /> 
     </EditText> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="vertical" > 

     <include layout="@layout/include_edit_buttons" /> 
    </LinearLayout> 

</RelativeLayout> 

回答

1

我認爲這應該工作:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
style="@style/fragmentBackdropPlain" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:orientation="vertical" 
    android:id="@+id/buttons"> 

    <include layout="@layout/include_edit_buttons" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:layout_above="@+id/buttons"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="@dimen/buttonText" 
     android:text="@string/subtopic_content_name" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 
    <TableRow android:id="@+id/tableRow1" android:layout_width="match_parent" android:layout_height="wrap_content"></TableRow> 

    <EditText 
     android:id="@+id/editSubTopicContent" 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:hint="@string/subtopic_content_hint" 
     android:inputType="textMultiLine" > 

     <requestFocus /> 
    </EditText> 

</LinearLayout> 

說明:
不同的是,現在他首先創建按鈕。創建按鈕後,您可以使用fill_parent作爲另一個佈局(linearLayout1)的高度,他將使用剩下的空間。如果你反過來寫它,他首先膨脹linearLayout1。由於佈局仍然是空的,所以fill_parent將佔據整個地方。然後沒有地方留下按鈕。

+0

輝煌,謝謝。如何聲明上面的按鈕使其工作?我只是假定按照我想要的順序放置它們,並告訴項目在上/下/相對於另一個不會影響XML中的順序。 –

+0

@尼爾我在答案中添加了一個解釋! – MalaKa

+0

啊,歡呼聲,我從來沒有想到這一點。現在我知道,當我得到佈局的其他問題時,它應該更有意義:) –