android 中的重叠 TransitionManager 动画

问题描述 投票:0回答:3

我正在尝试借助 TransitionManager 动画展开和折叠我的视图。以下是输出,

在折叠顶视图时查看重叠布局。如何避免这种情况?我设置“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");

                }
            }
        });
android android-animation android-transitions
3个回答
4
投票

我会以不同的方式构建动画。我会用带有 wrap_content 的顶部单元格制作一个 LinearLayout,点击时我会做类似的事情:

 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();

4
投票

我有同样的问题。

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)
}

0
投票

你能尝试设置你的过渡吗;

TransitionSet()
.setOrdering(TransitionSet.ORDERING_SEQUENTIAL)

/**
 * A flag used to indicate that the child transitions of this set
 * should all start at the same time.
 */
public static final int ORDERING_TOGETHER = 0;

/**
 * A flag used to indicate that the child transitions of this set should
 * play in sequence; when one child transition ends, the next child
 * transition begins. Note that a transition does not end until all
 * instances of it (which are playing on all applicable targets of the
 * transition) end.
 */
public static final int ORDERING_SEQUENTIAL = 1;
© www.soinside.com 2019 - 2024. All rights reserved.