0

I've problem similar to the one here: Android ListView doesn't expand the whole screen?

The XML is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/ResultLayout">

    <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
        <ListView android:layout_width="fill_parent" android:id="@+id/ListView"
            android:layout_height="fill_parent"></ListView>
    </ScrollView>
    <LinearLayout android:id="@+id/pagingPanel"
        android:gravity="center" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:orientation="horizontal"></LinearLayout>
    <Spinner android:layout_width="fill_parent" android:id="@+id/ManSpinner"
        android:layout_height="fill_parent" />
</LinearLayout>

In this case, I should have a ScrollView or the PagingPanel LinearLayout will disappear.

Edit

The desired layout is to have all the elements stacked on top of each other. but if the elements exceed the page height, a scroll should be added to the ListView.

halfer
  • 19,824
  • 17
  • 99
  • 186
Muhammad Hewedy
  • 29,102
  • 44
  • 127
  • 219

1 Answers1

1

If you have a vertical LinearLayout, You can't have multiple fill_parent for layout_height of your LinearLayout elements. What layout you would like to achieve? Uniformly divide screen for all elements?

Another problem is that using ListView in ScrollView is not a good idea also because ListView itself is scrollable.

You should write what layout you would like to achieve with your XML. Also generally is a good practice to write your XML in multiple steps and iterate to woking solution layout by layout.

EDIT: Ok, try something like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:id="@+id/ResultLayout">

    <ListView android:id="@+id/ListView"
        android:layout_width="fill_parent" 
        android:layout_height="0dp"
        android:layout_weight="1" />

    <LinearLayout android:id="@+id/pagingPanel"
        android:gravity="center" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:orientation="horizontal">

    </LinearLayout>

    <Spinner android:id="@+id/ManSpinner"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" />

</LinearLayout>
peter.bartos
  • 11,855
  • 3
  • 51
  • 62
  • It worked like a magic.. Many thanks!, BTW, can you provide me with a link to learn me how to layout components together.. I am very new to Android! – Muhammad Hewedy Sep 06 '11 at 15:33
  • I'm glad it helped. Few months ago when I started with android I had read these series of tutorials... and I think they are written very friendly: http://mobile.tutsplus.com/tutorials/android/android-layout/ – peter.bartos Sep 06 '11 at 15:39