如何创建一个布局,使其填充到底部另一个布局的位置

5

插图:

"----" 表示一个布局区域

"...." 表示另一个布局区域

<-------------------->
<----<TextView_1>---->
<-------------------->
<-<..<TextView_a...>-> 
<-<...          ...>->
<-<...          ...>->
<-<...         >...>->
<-<................>->
<-<................>->
<-<................>->
<-<..*layout_end*..>->
<-------------------->
<----<TextView_2----->
<-----         >----->
<-------------------->

"...."布局的内容只有一个TextView_a,这个控件不够大,无法填满直到*layout_end*的区域。

如果我在"...."布局中使用match_parent,那么TextView_2将不会出现。就像这样:

<-------------------->
<----<TextView_1>---->
<-------------------->
<-<..<TextView_a...>-> 
<-<...          ...>->
<-<...          ...>->
<-<...        />...>->
<-<................>->
<-<................>->
<-<................>->
<-<................>->
<-<................>->
<-<................>->
<-<................>->
<-<..*layout_end*..>->

我需要让“……”布局填满空间,但是留出一个空间给 TextView_2。我该怎么做才能得到所需的高度结果?就像这样:
<-------------------->
<----<TextView_1>---->
<-------------------->
<-<..<TextView_a...>-> 
<-<...          ...>->
<-<...          ...>->
<-<...         >...>->
<-<................>->
<-<................>->
<-<................>->
<-<..*layout_end*..>->
<-------------------->
<----<TextView_2----->
<-----         >----->
<-------------------->

正确:http://s30.postimg.org/f63iski0h/correto.png 错误:http://s11.postimg.org/jdq8al71f/incorreto.png


5
可以给我一些图片链接,而不是文字描述吗? - Phantômaxx
4个回答

7
创建一个垂直线性布局,如下所示:
<LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="mtch_parent"> 

     <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="48dip"/>        

     <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="0dip" android:layout_weight="1">

         <!-- put your TextView here -->
     </LinearLayout>


     <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="48dip"/> 
</LinearLayout>

0

用任何你想要的东西替换按钮,甚至是布局。

<Button
    android:id="@+id/topbutton"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_alignParentTop="true" >

</Button>

<Button
    android:id="@+id/bottombutton"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true" >

</Button>

<Button
    android:id="@+id/middlebutton"
    android:layout_width="40dp"
    android:layout_height="wrap_content"
    android:layout_above="@id/bottombutton"
    android:layout_below="@id/topbutton" >

</Button>


0

我想说的是,您可能想要一种活动,在这种活动中第一个TextView是标题,第二个是正文,第三个则为页脚。在这种情况下,wrap_content和match_parent将成为您的好朋友。

<LinearLayout 
 android:orientation="vertical" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent">
<TextView
    android:id="@+id/top"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:padding_top="15dp"
    android:padding_bottom="15dp">
<TextView
    android:id="@+id/middle"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:padding_top="5dp"
    android:padding_bottom="5dp">
<TextView
    android:id="@+id/bottom"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:padding_top="15dp"
    android:padding_bottom="15dp">
</LinearLayout>

顶部和底部的高度通过填充进行调整,而中间的则填充剩余的空间。


0
尝试使用另一个布局,然后将TextView2放置在该布局中。然后,当您将match_parent属性应用于布局1的高度时,它将适合于布局2。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接