cari

Rumah  >  Soal Jawab  >  teks badan

Animasi bar kemajuan dalam item recyclerview android - animasi bar kemajuan dalam item recyclerview

Tulis demo 想在recyclerview中 的item di mana bar kemajuan mempunyai kesan animasi

Hanya gunakan tetapan berterusansetProgress()的方式来写了,可是在实际过程中,会发生动画播放在不正确的item
即使我判断如果itemJika ia digunakan semula, tiada apa yang boleh anda lakukan jika anda membatalkannya. .


SparseIntArray sparseIntArray = new SparseIntArray();
ArrayMap<Integer, Disposable> arrayMap = new ArrayMap<>();

binding.recyclerView.setAdapter(new BaseRecyclerViewAdapter<Integer>(strings) {
    @Override
    public int getLayoutId(int viewType) {
        return R.layout.recycler_item;//item布局 其中有一个横向的进度条空间
    }

    @Override
    protected void convert(VH holder, Integer i, int position) {
  
        int after = sparseIntArray.get(position);        //查看item是否第一次使用
        Disposable disposable1 = arrayMap.get(position);
        if (disposable1 != null) {
            PtrCLog.d("RecyclerViewActivity", "convert: " + "取消订阅");
            disposable1.dispose();
        }

        if (after == i) {
            PtrCLog.d("RecyclerViewActivity", "convert: " + "相同后直接设置");
            holder.setProgress(R.id.progress_bar_financing_item, i);
        } else {
            sparseIntArray.put(position, i);//存
            int castProgress = (i);      //当前得到的
            PtrCLog.d("LoanListAdapter", "progress: " + castProgress);
            PtrCLog.d("LoanListAdapter", "初次生效当前坐标为: " + position + "-----" + "存储的进度为" + castProgress);
            Disposable disposable = Observable
                    .intervalRange(0, castProgress + 1, 0, 30, TimeUnit.MILLISECONDS)
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(aLong -> {
                                PtrCLog.d("LoanListAdapter", "convert: " + position + "----" + aLong + "");
                                PtrCLog.d("RecyclerViewActivity", "convert: after" + (after == i));
                                holder.setProgress(R.id.progress_bar_financing_item, Integer.parseInt(aLong + ""));
                            }, throwable -> {
                            }
                            , () -> {
                            });
            arrayMap.put(position, disposable);
        }
    }
});
    
扔个三星炸死你扔个三星炸死你2720 hari yang lalu1220

membalas semua(1)saya akan balas

  • 三叔

    三叔2017-06-08 11:04:32

    Pada masa hadapan, "animasi" seperti ini harus dilakukan dengan animasi sebanyak mungkin,

     ValueAnimator animator = ValueAnimator.ofInt(0, castProgress);
            animator.addUpdateListener(animation -> {
                int value = (int) animation.getAnimatedValue();
                holder.setProgress(R.id.progress_bar_financing_item, value);
            });
            animator.setDuration(2000);
            animator.start();

    balas
    0
  • Batalbalas