6

this is my layout (image):

https://i.stack.imgur.com/wPx04.jpg


What I want to do is make the 1st LinearLayout 50dip high (this is already OK), then have the 3rd LinearLayout also 50dip high from the bottom up - and then make the 2nd LinearLayout fill the place left inbetween. How do I do it?


This is my XML:

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" >

</LinearLayout>


<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/linearLayout1"
    android:orientation="vertical" >

    <ViewFlipper
    android:id="@+id/viewFlipper1"
    android:layout_width="match_parent"
    android:layout_height="fill_parent" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/rain1" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/thunder1" />

    </ViewFlipper>

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout3"
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/linearLayout2">

</LinearLayout>

</RelativeLayout>
c0dehunter
  • 6,412
  • 16
  • 77
  • 139

6 Answers6

17

Wrap all three layouts in a vertical Linear Layout and use a layout weight of "1" on the middle layout:

<LinearLayout
    .
    .
    . 
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <LinearLayout 
        .
        .
        .
        android:layout_height="50dip">
    <LinearLayout 
        .
        .
        .
        android:layout_height="0dp"
        android:layout_weight="1">
    <LinearLayout 
        .
        .
        .
        android:layout_height="50dip">
</LinearLayout>
Mark Allison
  • 21,839
  • 8
  • 47
  • 46
1

Convert LinearLayout into Relative layout. define relative position of element. your problem will get solved

Or use weight in linear layout. define weight 1.0 for second linear layout.and for top parent layout height and width should be fill_parent

1

I haven't added your drawables in this code but I believe this should fix your problem:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" >

</LinearLayout>


<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/linearLayout1"
    android:layout_above="@+id/linearLayout3"
    android:orientation="vertical" >

    <ViewFlipper
    android:id="@+id/viewFlipper1"
    android:layout_width="match_parent"
    android:layout_height="fill_parent" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />

    </ViewFlipper>

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout3"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true" >

</LinearLayout>


</RelativeLayout>
Ghost
  • 3,966
  • 1
  • 25
  • 36
1

Try this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
              android:orientation="vertical" 
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent"
              >
    <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="50dip" 
        android:background="#FF00FF"    
        android:id="@+id/first"    
        />   
     <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="50dip" 
        android:background="#0000FF"
        android:id="@+id/last"    
        android:layout_alignParentBottom="true"         
       />        
     <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:background="#FFFFFF"
        android:layout_above="@id/last" 
        android:layout_below="@id/first"    
        >
        <ViewFlipper
            android:id="@+id/viewFlipper1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >       
                <ImageView
                    android:id="@+id/imageView1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:src="@drawable/rain1" />        
                <ImageView
                    android:id="@+id/imageView2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:src="@drawable/thunder1" />     
        </ViewFlipper>

    </LinearLayout>
</RelativeLayout>
Hiral Vadodaria
  • 19,158
  • 5
  • 39
  • 56
0
LinearLayout layout;
layout.addView(child, 2);
Yahor10
  • 2,123
  • 1
  • 13
  • 13
0

try put the 3rd layout before the 2nd one

<Relativelayout>
    <Linearlayout1>
    <Linearlayout3>
    <linearlayout2>
</Relativelayout>
JohnCookie
  • 661
  • 3
  • 7
  • I tried this but the result is the same. What I am also wondering is why is the 3rd layout so big if the height is set to 50dip?! – c0dehunter Feb 01 '12 at 11:43