Android 下面的 TransitionManager Views 没有动画

Android TransitionManager Views below not animated

ScreenRecording

我喜欢顶部 cardView 的动画,但下面的视图没有动画,只是卡在原地。如何以不重叠的方式为它们制作动画?这不是 recyclerView,这些是单独的 cardView。

顶部 CardView 的代码:

imageViewMuellExtend = (ImageView) root.findViewById(R.id.imageViewMuellExtend);
    imageViewMuellExtend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            muell_extend = (ConstraintLayout) root.findViewById(R.id.muell_extend);
            cardViewMuell = (CardView) root.findViewById(R.id.cardViewMuell);

            if(muell_extend.getVisibility() == View.GONE){
                TransitionManager.beginDelayedTransition(cardViewMuell, new AutoTransition());
                muell_extend.setVisibility(View.VISIBLE);
                imageViewMuellExtend.setBackgroundResource(R.drawable.ic_keyboard_arrow_up_black_24dp);
            } else {
                TransitionManager.beginDelayedTransition(cardViewMuell, new AutoTransition());
                muell_extend.setVisibility(View.GONE);
                imageViewMuellExtend.setBackgroundResource(R.drawable.ic_keyboard_arrow_down_black_24dp);
            }
        }
    });

XML CardView 布局:

<androidx.cardview.widget.CardView
        android:id="@+id/cardViewMuell"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        app:cardCornerRadius="8dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="16dp">

                <ImageView
                    android:id="@+id/imageViewMuellIcon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="16dp"
                    android:src="@drawable/ic_delete_black_24dp"
                    android:tint="@color/colorAccent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:text="Müll"
                    android:textColor="#000000"
                    android:textSize="18sp"
                    app:layout_constraintBottom_toBottomOf="@+id/imageViewMuellIcon"
                    app:layout_constraintStart_toEndOf="@id/imageViewMuellIcon"
                    app:layout_constraintTop_toTopOf="@+id/imageViewMuellIcon"
                    app:layout_constraintVertical_bias="0.0" />

                <ImageView
                    android:id="@+id/imageViewMuellExtend"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_margin="16dp"
                    android:background="@drawable/ic_keyboard_arrow_down_black_24dp"
                    app:layout_constraintBottom_toBottomOf="@+id/imageViewMuellIcon"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="@+id/imageViewMuellIcon" />

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:id="@+id/muell_extend"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:visibility="gone"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/imageViewMuellIcon">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="8dp"
                        android:text="@string/info_muell"
                        android:textColor="#000000"
                        android:textSize="18sp"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
                </androidx.constraintlayout.widget.ConstraintLayout>


            </androidx.constraintlayout.widget.ConstraintLayout>


        </androidx.cardview.widget.CardView>

这个 Fragment 中的每个 CardView 看起来都是这样的,并且项目只是重命名了。

您传递给 TransitionManager.beginDelayedTransition 的第一个参数是 sceneRoot。转换只会影响 sceneRoot 内部的视图,不会影响外部的视图。

您将 cardViewMuell 作为此参数传递,这意味着转换将在单击的卡片内为视图设置动画,但在其他卡片的 none 内设置视图动画。尝试传递包含所有卡片的 sceneRoot