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

3
  • You cant do that if you use fill_parent for height. Nov 11, 2013 at 9:20
  • How do you stop getview from getting called ? It will get called the number of times as the size of list items. Nov 11, 2013 at 9:20
  • not clear what are you trying to achieve Nov 11, 2013 at 9:24

5 Answers 5

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>
1
  • 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 stackoverflow.com/a/2639159/1768336.
    – Link 88
    Nov 11, 2013 at 9:43
0

Try to use following code

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

in ListView tag

1
  • With this solution, GetView will be called more times than needed. Already tried.
    – Link 88
    Nov 11, 2013 at 9:33
0

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

2
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.

5
  • 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, 2013 at 9:40
  • you can add 'android:minHeight="100dp"' too.
    – invisbo
    Nov 11, 2013 at 9: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, 2013 at 9:57
  • Then add 'android:maxHeight="100dp"' to view at below.
    – invisbo
    Nov 11, 2013 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, 2013 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>
2
  • why don't you put wrap_content to ListView height instead of creating LL and assign its height as Wrap_content ?
    – krishna
    Nov 11, 2013 at 9: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, 2013 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.