Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a layout to fill the space until another layout at the bottom

Ilutration:

"----" indicates a Layout area

"...." indicates another Layout area

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

The content of the "...." layout is just TextView_a, that isn't big enough to fill until the *layout_end*.

If I put match_parent in the "...." layout, the TextView_2 doesn't appear. Like this:

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

I need to "...." layout fills the space, but leave a space just for the TextView_2. What can I do to have the hight result? That result:

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

Right: http://s30.postimg.org/f63iski0h/correto.png Wrong: http://s11.postimg.org/jdq8al71f/incorreto.png

like image 835
Mateus Pires Avatar asked Dec 29 '13 17:12

Mateus Pires


1 Answers

create a vertical linear layoutlike this:

<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>
like image 167
Ali Behzadian Nejad Avatar answered Oct 14 '22 21:10

Ali Behzadian Nejad