1

To prevent multiple GetView calling I have set the height of ListView to fill_parent.

How to show other views than the ListView itself?

The following layout is inflated in a ViewPager:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="15dp" >

    <ListView android:id="@+id/lv_viol_infraction"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <include layout="@layout/activity_prontuario_home" />
</LinearLayout>

where the included layout is:

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

    <ScrollView
        android:id="@+id/prontuariohome_scrollview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none" >
        .
        .
        .
        .
    </ScrollView>

</LinearLayout>

EDIT: This solution won't work for view higher than a button

Community
  • 1
  • 1
Link 88
  • 553
  • 8
  • 27

5 Answers5

1

I don't understand what you want to achieve, but if you NEED to have the height as fill_parent for some reason and can't be any other value, you can put the ListView with inside a LinearLayout with the height="0dp" and weight="1". So would be something like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="15dp" >

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

    <include layout="@layout/activity_prontuario_home" />
</LinearLayout>
josebama
  • 848
  • 8
  • 11
  • Almost the solution I found! Yes, of course you need to set fill_parent, otherwise you will have the GetView method called more times than neede as explained here http://stackoverflow.com/a/2639159/1768336. – Link 88 Nov 11 '13 at 09:43
0

Try to use following code

android:layout_height="0dp"
android:layout_weight="1" 

in ListView tag

Sanket Shah
  • 4,352
  • 3
  • 21
  • 41
Apoorv
  • 13,470
  • 4
  • 27
  • 33
0

With android:layout_height="0dip" the view will take the rest of the free place

momor10
  • 478
  • 3
  • 11
  • With this solution, GetView will be called more times than needed. Already tried. – Link 88 Nov 11 '13 at 09:34
  • it's no problem for getView to be called multiple times http://stackoverflow.com/questions/9157523/listview-getview-is-called-too-much-times – momor10 Nov 11 '13 at 11:09
0

You said this solution is wont work:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/lv"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white" android:layout_above="@+id/bt"/>
<Button android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:id="@+id/bt" android:layout_alignParentBottom="true"/>

just add it a android:layout_above="@+id/bt" to listview.

invisbo
  • 3,399
  • 1
  • 16
  • 20
  • Yes because if you have a View with an high height, it will overlap the ListView. It's a workaround for small view only. Already tried to add layout_above, same behaviour. – Link 88 Nov 11 '13 at 09:40
  • you can add 'android:minHeight="100dp"' too. – invisbo Nov 11 '13 at 09:53
  • So bad solution, I would have a fixed height, and adding more items to the list view I will encounter graphic layout problem. – Link 88 Nov 11 '13 at 09:57
  • Then add 'android:maxHeight="100dp"' to view at below. – invisbo Nov 11 '13 at 10:06
  • In my humble opinion you have to make layout as much generic as possible. Using min/maxHeight in this case, you lose this "generic rule" – Link 88 Nov 11 '13 at 10:24
0

I'm sorry for being not clear.

Here is the link of the (probably) main thread asked here in Sof about the issue I was talking about.

After some tries I'm happy to give you the solution of my problem.

Giving another layout above the ListView lets the LV cuts the space not filled by the ListView itself

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="15dp" >

    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <ListView android:id="@+id/lv_viol_infraction"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>

    <include layout="@layout/activity_prontuario_home" />
</LinearLayout>
Community
  • 1
  • 1
Link 88
  • 553
  • 8
  • 27
  • why don't you put wrap_content to ListView height instead of creating LL and assign its height as Wrap_content ? – krishna Nov 11 '13 at 09:46
  • Like said below, you need to set fill_parent, otherwise you will have the GetView method called more times than neede as explained here stackoverflow.com/a/2639159/1768336. – Link 88 Nov 11 '13 at 09:58