Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improving Scroll Smoothness in an Android ListView

I have a an Android ListView that has small (say, 1-5 frame) stutters as it is scrolling, about every second or so. I realize that many Android phones have these problems with animation smoothness, however, on my phone (Motorola A855 running Android 2.2), the native contact list scrolls quite smoothly. The item view in the contact list is more complex than the item view in my list, which is:

<RelativeLayout>
    <TextView />
    <TextView />
</RelativeLayout>

I only want to achieve smoothness as good as the native contact list. It seems like this should be possible without optimizing in native code, but perhaps I'm wrong about that.

I have tried a few things: I simplified the item view even further, and I tried instantiating it programmatically instead of in XML. I also tried changing the way I react to item click events, as per this link:

http://groups.google.com/group/android-developers/browse_thread/thread/7dc261a6b382ea74?pli=1

None of these things seem to have any effect on performance.

Is there anything I can do in my app to improve performance? I'm looking to deploy this app to a number of phones, so changing settings on the phone or rooting the device is not an option in my case. Here is the getView method from my adapter class:

    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater flater = (LayoutInflater)context.getSystemService(ListActivity.LAYOUT_INFLATER_SERVICE);
        layout = flater.inflate(R.layout.song_view, parent, false);
        TextView first = (TextView)layout.findViewById(R.id.firstLine);
        TextView second = (TextView)layout.findViewById(R.id.secondLine);

        Thing t = array.get(position);
        first.setText(t.title);
        second.setText(t.name);
        return layout;
    }

Thanks in advance!

like image 992
charleslparker Avatar asked Jun 09 '11 13:06

charleslparker


People also ask

How to increase scrolling smoothness in Android?

Uninstall bloatware and unused apps Additionally, too much bloatware and unused apps can cripple your device's performance. In case you have apps you're not using or many preinstalled apps on your device, consider uninstalling or disabling them to make your phone run faster. Gently scroll through the apps.

Does ListView have scroll?

A ListView in Android is a scrollable list used to display items.

Is ListView scrollable by default?

scrollable Boolean|String (default: false) If set to true the listview will display a scrollbar when the content exceeds the listview height value. By default scrolling is disabled. It could be also set to endless in order to enable the endless scrolling functionality.


1 Answers

It's difficult to know why this may be happening without seeing your code.

However, one place to look is your getView() method in your ListAdapter (assuming you're using a custom adapter). Try and re-use the View that's passed as an argument to this method rather than creating a new one each time. Also don't do anything too heavy in this method (e.g. a network call), in fact try to make it as lean and mean as possible for best performance.

like image 68
Mark Allison Avatar answered Sep 30 '22 18:09

Mark Allison