0

我正在尝试扩展recycleview 并为viewHolder 设置动画,但是当我展开recycleView 时Animation animateAdd 不起作用。请帮我

    @Override
    public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        recyclerView.setItemAnimator(new DefaultItemAnimator() {
            @Override
            public boolean animateAdd(RecyclerView.ViewHolder holder) {
                Log.d(TAG, "animateAdd: ");
                return super.animateAdd(holder);   
            }
     }

private void expandRv(int preHeight) {
        int targetHeight = 1000;
        ValueAnimator valueAnimator = ValueAnimator.ofInt(preHeight, targetHeight);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mRecyclerView.getLayoutParams().height = (int) animation.getAnimatedValue();
                mRecyclerView.requestLayout();
            }
        });
        valueAnimator.setInterpolator(new DecelerateInterpolator());
        valueAnimator.setDuration(1000);
        valueAnimator.start();
    }
4

0 回答 0