我试图在TransitionManager动画的帮助下展开和折叠我的视图。以下是输出,
折叠顶视图时查看重叠布局。怎么避免呢?我设置了#34; detailedView" (带有图标的一个)可见性GONE
并使用以下代码进行动画,
topView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TransitionManager.beginDelayedTransition(topView);
TransitionManager.beginDelayedTransition(bottomView);
if (detailsView.getVisibility() == View.VISIBLE) {
detailsView.setVisibility(View.GONE);
cardText.setText("Collapse Title");
} else {
detailsView.setVisibility(View.VISIBLE);
cardText.setText("Expanded Title");
}
}
});
答案 0 :(得分:2)
I would build the animation differently. I would make a LinearLayout with the top cell with wrap_content, and when clicking I would do something like:
valueAnimator = ValueAnimator.ofInt(titleContainer.getHeight(),titleContainer.getHeight() + newHeight );
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
titleContainer.setHeight(animation.getAnimatedValue());
}
});
valueAnimator.setDuration(270);
valueAnimator.start();
答案 1 :(得分:1)
我有同样的问题。
TransitionManager.beginDelayedTransition()
函数采用的第一个参数必须是将在过渡中交互的所有视图的父级,例如:
我有下一个布局:
<!-- The scene root -->
<LinearLayout
android:id="@+id/transition_container" >
<!-- First card -->
<androidx.cardview.widget.CardView
android:id="@+id/expandableCard1">
<LinearLayout
android:id="@+id/staticHeader1">
</LinearLayout>
<LinearLayout
android:id="@+id/expandableContent1">
</LinearLayout>
</androidx.cardview.widget.CardView>
<!-- Second card -->
<androidx.cardview.widget.CardView
android:id="@+id/expandableCard2">
<LinearLayout
android:id="@+id/staticHeader2">
</LinearLayout>
<LinearLayout
android:id="@+id/expandableContent2">
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
还有我的代码(kotlin):
// toggle
if( expandableContent1.visibility == View.GONE ){
// apply to the root scene
TransitionManager.beginDelayedTransition(transition_container )
// change the visibility of the expandable content
expandableContent1.visibility = View.VISIBLE
arrowBtn.setImageResource( R.drawable.ic_arrow_up_24)
} else {
// apply to the root scene
TransitionManager.beginDelayedTransition(transition_container )
// change the visibility of the expandable content
expandableContent1.visibility = View.GONE
arrowBtn.setImageResource( R.drawable.ic_arrow_down_24)
}