1

I have a ListView with over 1,000 items and a scrollbar. When scrolling without using the scrollbar, the scrollbar does not scroll smoothly. Instead it initially goes in the direction you expect it to, then jumps backwards. While scrolling, it jumps backwards several times, instead of scrolling through the list smoothly. In my XML layout for the ListView, I have specified android:smoothScrollbar="false" as an attempt to remedy this. documentation. However, the issue still persists. All of my items are of the same height. How can I get my scrollbar to scroll smoothly?

Here is my XML

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

<ListView
    android:id="@id/android:list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fastScrollEnabled="true"/>

<TextView
    android:id="@id/android:empty"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/no_songs_found"
    android:textColor="@color/asbestos"
    android:textSize="24sp"
    android:gravity="center"/>
</FrameLayout>
Andrew Orobator
  • 7,978
  • 3
  • 36
  • 36

3 Answers3

0

This is an Example of what i did a long time ago, did u do ur xml like this

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fadingEdge="horizontal"
    android:fillViewport="true"
    android:scrollbars="horizontal" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/whitesmoke"
        android:orientation="vertical"
        android:textColor="@color/Black" >

        <TextView
            android:id="@+id/path"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/Black" />



        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="408dp"
            android:textColor="@color/Black" />

        <TextView
            android:id="@android:id/empty"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="No Data" />

        <!--
             <ImageView
            android:id="@+id/Thumbnail"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/icon" />
        -->
    </LinearLayout>

</ScrollView>
ImGeorge
  • 527
  • 6
  • 24
  • I've added my XML above. I didn't have my ListView in a ScrollView and I have fastScroll enabled. – Andrew Orobator Dec 19 '13 at 18:56
  • Did you try to wrap it in a scrollview see whether it still works – ImGeorge Dec 19 '13 at 18:57
  • The [documentation for scrollview](http://developer.android.com/reference/android/widget/ScrollView.html) specifically says never to put a ListView in a ScrollView. "You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView." – Andrew Orobator Dec 19 '13 at 19:02
  • Sometimes i just do what works so i can move unto anoda project.. Android is still very new and most of their stuff especially XML is still very buggy. – ImGeorge Dec 19 '13 at 19:05
  • Even if it did work, my listview would consume a lot of memory. I would be displaying thousands of items all at once which is completely unnecessary. It would also slow down my app tremendously. – Andrew Orobator Dec 19 '13 at 19:07
  • Where you putting the 1000 items is it in the xml – ImGeorge Dec 19 '13 at 19:09
  • Found this links hope it helps: http://stackoverflow.com/questions/5312592/how-can-i-get-my-listview-to-scroll http://nex-otaku-en.blogspot.com/2010/12/android-put-listview-in-scrollview.html – ImGeorge Dec 19 '13 at 19:41
0

Just a thought, if you're testing on a real device, make sure it's not plugged into your dev machine. I've noticed interference on the touchscreen before that sounds similar to your issue.

Ljdawson
  • 12,091
  • 11
  • 45
  • 60
0

I was using an arraylist for my adapter. Using a cursoradaptor, list scrolling was much better. I guess arraylists can't handle that much data.

Andrew Orobator
  • 7,978
  • 3
  • 36
  • 36