zoukankan      html  css  js  c++  java
  • 更新RecyclerView的好方法

      一般在使用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);
                }
            }
        }        
  • 相关阅读:
    Buffer -nodejs
    Tip提示框另类写法
    SASS入门
    界面设计必须要权衡的三个要素
    如何快速出稿一个优秀APP的构图
    如何画好一套线性图标
    Ui培训之如何设计极简三色图标
    移动APP设计国外资源总汇
    移动界面UI颜色设计
    APP专业视觉设计基础标准要求
  • 原文地址:https://www.cnblogs.com/zhangmiao14/p/7002272.html
Copyright © 2011-2022 走看看