List View Scroll Not Smooth

五迷三道 提交于 2019-12-01 18:39:40

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.

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() {
public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCoun) {
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
        if (scrollState != 0)
            listView.getAdapter()).isScrolling = true;
        else {
            adapter.isScrolling = false;
            adapter.notifyDataSetChanged();
        }
} });

add into Adapter class

public static Boolean isScrolling = true;

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

  1. Use Holder pattern and re-using the views in the getView() of list adapter
  2. Use some async image loading library for downloading images that you display in the ListView? For e.g. Universal Image Loader
  3. 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!