-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
  • 195,986
  • 40
  • 382
  • 396
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
  • 143
  • 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
  • 28,756
  • 7
  • 51
  • 55
  • 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,082
  • 2
  • 22
  • 26
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,218
  • 2
  • 28
  • 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.
  • 28,804
  • 3
  • 80
  • 126
0

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

Jave
  • 31,050
  • 14
  • 76
  • 90
Dhaval Patel
  • 694
  • 4
  • 12