Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List View Scroll Not Smooth

i have a custom list view, which displays users, and there photos i retrieve the data from API, Which gives JSON Output,

My Issue is that the list view is not scrolling smoothly, it hangs for a sec and scrolls, it repeats the same till we reach the end.

i thought it might me because i am running network related operation on the UI thread, but it continues to do that even after it completes loading?

the structure of my custom Listview is

 <TextView  style="@style/photo_post_text"
             android:id="@+id/photo_post_text"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="demotext"
           />


        <ImageView
            android:id="@+id/userimage"
           android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"

            android:adjustViewBounds="true"
           android:src="@drawable/pi" 
           />
like image 505
Robert Ray Avatar asked Dec 15 '22 04:12

Robert Ray


1 Answers

Use an AsyncTask for the loading of your pictures. The scrolling will not be smooth as long as you do such tasks in the UI thread.

Have a look at this tutorial. It will help you understand what you need to implement without the need of additional libraries. Also please keep in mind that the rows are redrawn all the time while you scroll, there's no real "finishing" of loading. You can additionally consider an image-cache, e.g. with a ConcurrentHashMap in which you could put your loaded pictures.

like image 145
Blacklight Avatar answered Jan 01 '23 18:01

Blacklight