2

Help me with XML layout.

I have three LinearLayout on activity, all LinearLayout have position vertical (from top to bottom)

My LinearLayout positions

  1. first LinearLayout have android:layout_height="30px", android:layout_width="fill_parent"
  2. second LinearLayout have android:layout_height="fill_parent", android:layout_width="fill_parent"
  3. third LinearLayout have android:layout_height="30px",android:layout_width="fill_parent"

But when second LinearLayout set as fill_parent it fill full screen (from first Layout to bottom of screen), and third LinearLayout cant display!

How i need fill the second layout?

Help me

Nompumelelo
  • 929
  • 3
  • 17
  • 28
Serjaru
  • 89
  • 1
  • 9

5 Answers5

3

Use this one simply.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainLinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#fbfbfb"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:orientation="horizontal" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.9"
    android:orientation="vertical" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:orientation="horizontal" />
</LinearLayout>
</LinearLayout>
Piyush
  • 18,895
  • 5
  • 32
  • 63
2

You can use relative layout for your purpose:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:orientation="vertical" >
</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:orientation="vertical" >
</LinearLayout>

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

</RelativeLayout>
Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
0

The trick is to not use fill_parent for this but 0dp and give it a weight with android:layout_weight="1". This means that it will take all available extra space

Ivo
  • 18,659
  • 2
  • 23
  • 35
0

You have to give weight to middle linear layout so it can take full height.

try this for middle linear layout,

   <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >
    </LinearLayout>
Jatin
  • 1,650
  • 3
  • 17
  • 32
0

If you set height="fill_parent" to the middle layout, it will take the height of the parent view, so the 3rd view will not be visible (out of the screen)

1st layout : android:layout_height="30px", android:layout_width="match_parent"
2nd layout : android:layout_height="0dp", android:layout_width="match_parent", android:layout_weight="1"
3rd layout : android:layout_height="30px", android:layout_width="match_parent"

You should use "dp" instead of "px", to get the same size on different screen densities.

("fill_parent" is deprecated, you should use "match_parent", it does the same)

Jfreu
  • 511
  • 5
  • 10