自学内容网 自学内容网

Android实现RecyclerView宽度变化动画

效果图

实现思路就是定义一个属性动画,在动画监听器中不断修改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


原文地址:https://blog.csdn.net/y280903468/article/details/142826221

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!