一般在使用RecyclerView的時候不免要修改RecyclerView的數據,使用notifyDataSetChanged()來刷新界面,但是當數據比較多,而只是修改了一點的數據,或者刷新比較頻繁,這樣就會導致界面的卡頓問題,用戶交互特別不好。
這個時候就需要只是修改需要修改的數據,不要將數據全部進行更新,這樣就可以解決問題。
局部更新的代碼如下:
private int position;//當前recyclerview的position@BindView(R.id.speak_valuate_recycler_view)RecyclerView recyclerView;private LinearLayoutManager mRecyclerViewLayoutManager;mRecyclerViewLayoutManager = new LinearLayoutManager(this);mRecyclerViewLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);recyclerView.setLayoutManager(mRecyclerViewLayoutManager);private void changVolume(final int volume) { int first = mRecyclerViewLayoutManager.findFirstVisibleItemPosition(); int last = mRecyclerViewLayoutManager.findLastVisibleItemPosition(); if (position >= first && position <= last) { View view = recyclerView.getChildAt(position - first); if (recyclerView.getChildViewHolder(view) instanceof SpeakContentAdapter.SpeakContentHolder) { //修改數據 ProgressImageView progressImageView = (ProgressImageView) view.findViewById(R.id.speak_item_record); progressImageView.setProgress(volume); } } } 以上所述是小編給大家介紹的Android 更新RecyclerView的好方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答