效果图
实现思路就是定义一个属性动画,在动画监听器中不断修改RecyclerView的宽度
valueAnimator = ValueAnimator.ofInt(begin, recyclerView.getWidth() * 2);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(@NonNull ValueAnimator valueAnimator) {
Log.e("YinTest_", "onAnimationUpdate getAnimatedValue=" + valueAnimator.getAnimatedValue());
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) recyclerView.getLayoutParams();
layoutParams.width = (int) valueAnimator.getAnimatedValue();
// layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
recyclerView.setLayoutParams(layoutParams);
recyclerView.setX((begin * 2 - layoutParams.width));
}
});
valueAnimator.start();
// recyclerView.getAdapter().notifyDataSetChanged();
recyclerView.getAdapter().notifyItemRangeChanged(layoutManager.findFirstVisibleItemPosition(), 36);
完整Demo
https://download.csdn.net/download/y280903468/89871840