List View Scroll Not Smooth
Solution 1:
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.
Solution 2:
For Image Load quickly use this lib it is very faster to load images https://github.com/bumptech/glide
For List view Scroll smooth use strictMode .IT write in activity onCreate() method
protected void onCreate(Bundle savedInstanceState) {
//StrictMode for smooth list scroll
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*-----
ListView
Custom Adapter set data....
------*/}
on more thing to add in to onCreate() method
listView.setOnScrollListener(new OnScrollListener() {
publicvoidonScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCoun) {
}
publicvoidonScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState != 0)
listView.getAdapter()).isScrolling = true;
else {
adapter.isScrolling = false;
adapter.notifyDataSetChanged();
}
} });
add into Adapter class
publicstaticBooleanisScrolling=true;
Solution 3:
There can be quite a few reasons for not so smooth scrolling of ListView. You can make sure you are using some of the best practices like
- Use Holder pattern and re-using the views in the
getView()
of list adapter - Use some async image loading library for downloading images that you display in the ListView? For e.g. Universal Image Loader
- Use
AsyncTask
to download JSON from network and all the network related processing is done in separate thread.
Once you make sure you have covered the above, it should work good.
Post a Comment for "List View Scroll Not Smooth"