-2

I'm having problems with a layout in wich I have two buttons (working fine) and a listview wrapped by a scrollview.

The problem is that the list is shown but I can only see one element, I can scroll but the rest of the screen is wasted and I want the listview to be displayed as big as it can be.

Here is my layout XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Enviar" >

<LinearLayout
    android:id="@+id/layhoriz"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/b_arriba"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Arriba" />

    <Button
        android:id="@+id/b_salir_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Salir" />
</LinearLayout>

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/ListView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ListView>
</ScrollView>

Mat
  • 202,337
  • 40
  • 393
  • 406
Victor
  • 23
  • 1
  • 6

6 Answers6

1

Try to use a ListView element without scrollview, the scroll works on the ListView when the number of elements are more than the elements displayed on the screen.

Damzeloca
  • 153
  • 1
  • 6
1

Here is the duplicate questions for listview inside scrollview...

Android ListView rows in ScrollView not fully displayed - clipped

ListView inside ScrollView is not scrolling on Android

ListView inside a ScrollView

Community
  • 1
  • 1
Hariharan
  • 24,741
  • 6
  • 50
  • 54
  • Ok, the problem was that the listview is already scrollable, so I don't need to wrap it with any scrollview – Victor Aug 22 '13 at 14:30
1

There is no need to use the scroll view over the list view

Manmohan Soni
  • 6,472
  • 2
  • 23
  • 29
0

Its not a best practice to put any vertically scrollable viewgroup inside another vetical scrolling viewgroup/container.

Have a look a here.

If you anyway want to achieve it, look at the answer given in the same post.

Community
  • 1
  • 1
Purush Pawar
  • 4,263
  • 2
  • 29
  • 37
0

You don't put Auto expanding views ( like ListView) in a ScrollView.

ScrollView is set to expand for its contents and provide scrolling, it has no height/width of its own set. So, its child view should not try to match_parent.

Mark the ListView to have a fixed height.

I recommend watching this google presentation, about ListViews.

S.D.
  • 29,290
  • 3
  • 79
  • 130
0

ListView will scroll its contents automatically, so there is no need to use a ScrollView.

Jave
  • 31,598
  • 14
  • 77
  • 90
Dhaval Patel
  • 694
  • 4
  • 12