2014-02-12 55 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

啊,欢呼声,我从来没有想到这一点。现在我知道,当我得到布局的其他问题时,它应该更有意义:) –