写一个demo
想在recyclerview
中 的item
中的进度条有动画效果
就用不断设置setProgress()
的方式来写了,可是在实际过程中,会发生动画播放在不正确的item
上
即使我判断如果item
是被复用的话则取消也无能为力。。
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);
}
}
});
以后这种“动画”尽量还是用动画来做吧,