我喜欢顶部的卡片视图的动画,但下面的视图没有动画,只是卡在原地。我怎样才能使它们的动画效果不重叠?这不是一个recyclerView,这些是单独的CardViews。
顶部的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);
}
}
});
CardView的XML布局
<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>
这个片段中的每个CardView都是这样的,项目只是重命名而已。
你传入的第一个参数是 TransitionManager.beginDelayedTransition
是 sceneRoot
. 过渡只会影响到内部的视图。sceneRoot
,没有任何外在的东西。
你要过去了 cardViewMuell
作为这个参数,这意味着过渡将对点击的卡片内部的视图进行动画处理,而对其他卡片则没有。试着通过一个 sceneRoot
的,包含所有的卡。