Why is my list not scrolling?

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#dad4c8"
    android:gravity="center_horizontal">
    <include
        android:id="@+id/title_bar"
        layout="@layout/title_bar" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/title_bar"
        android:id="@+id/txt"
        android:hint="Song title" />

    <ListView
        android:cacheColorHint="#00000000"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/txt"
        android:id="@+id/list" />

</RelativeLayout>
+7
source share
4 answers

Use LinearLayout and set ListView Height to 0dip and give it layout_weight="1"

This will allow you to autofill any remaining space, as a result of which the internal elements of the list scroll. The list is currently very high and is trimmed by the borders of the screen.

Edit

Something like that:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#dad4c8"
    android:orientation="vertical"
    android:gravity="center_horizontal">
    <include
        android:id="@+id/title_bar"
        layout="@layout/title_bar" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txt"
        android:hint="Song title" />

    <ListView
        android:cacheColorHint="#00000000"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:id="@+id/list" />

</LinearLayout>
+17
source

In the interest of the community, I will invest in what does not work for me and what worked. This is the only message that helped solve the problem, others were just a lecture. Thanks @Kurru

I tried to reduce the shit. Areas for focus: android:layout_height android:layout_weight.

Does not work

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"/>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content />
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbarSize="3dp"
        android:scrollbarStyle="outsideOverlay"
        android:scrollbars="vertical"
        android:scrollingCache="true"
        android:smoothScrollbar="true" />
</LinearLayout>

Worked

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:scrollbarSize="3dp"
        android:scrollbarStyle="outsideOverlay"
        android:scrollbars="vertical"
        android:scrollingCache="true"
        android:smoothScrollbar="true" />
</LinearLayout>
+1

For those still looking for an answer, follow this link, you just need to do this inchild scroll view by adding android: nestedScrollingEnabled = "true" to your XML declaration or explicitly calling setNestedScrollingEnabled (true).

0
source

You must add a property android:scrollbarswith a value verticalto your ListView to add a scroll bar to your List:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#dad4c8"
    android:gravity="center_horizontal">
    <include
        android:id="@+id/title_bar"
        layout="@layout/title_bar" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/title_bar"
        android:id="@+id/txt"
        android:hint="Song title" />

    <ListView
        android:cacheColorHint="#00000000"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/txt"
        android:id="@+id/list" 
        android:scrollbars="vertical"/>

</RelativeLayout>
-2
source

All Articles