【问题标题】:How to animate viewflipper with two childs that have different heights如何为具有不同高度的两个孩子制作取景器动画
【发布时间】:2017-10-24 05:15:31
【问题描述】:
 <ViewFlipper
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:measureAllChildren="false">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="200dp">
    </RelativeLayout>

</ViewFlipper>

我有视图脚蹼。并且 animation 改变视图工作正常:

Animation slideDown = AnimationUtils.loadAnimation(getActivity(), android.R.anim.slide_in_left);
slideDown.setDuration(900);
Animation slideUp = AnimationUtils.loadAnimation(getActivity(), android.R.anim.slide_out_right);
slideUp.setDuration(300);

mReceiverFlipper.setInAnimation(slideDown);
mReceiverFlipper.setOutAnimation(slideUp);

我的问题是我的 flipperView 无法垂直设置动画。由于两个子视图具有不同的高度。当我在childViews 我的fipperView 之间切换时,在没有animation 的情况下调整他的高度。

那么,当 FlipperView 的尺寸发生变化时,我该如何为其设置动画呢?

【问题讨论】:

  • 不要将具有固定高度的直接子级(RelativeLayout)放入 ViewFlipper 中,而是为每个子级多使用一个父级布局。
  • @HareshChhelana 它将如何解决问题?如果我用另一个包装我的 relativeLayout 会发生什么变化?

标签: android animation android-animation viewflipper android-viewflipper


【解决方案1】:

您可以使用android:animateLayoutChanges 属性。

在 ViewFlipper 上添加属性 android:animateLayoutChanges 并将其设置为 true。 (&lt;ViewFlipper android:animateLayoutChanges="true" ...)

然后在你的代码中,你需要添加这一行来启用动画:

((ViewFlipper) findViewById(/* your viewflipper id here*/)).getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING)

或在 Kotlin 中:

findViewById<ViewFlipper>(/* your viewflipper id here*/).layoutTransition.enableTransitionType(LayoutTransition.CHANGING)

来源:https://proandroiddev.com/the-little-secret-of-android-animatelayoutchanges-e4caab2fddec

【讨论】:

    猜你喜欢
    • 2014-10-21
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    • 2017-03-22
    • 2020-01-02
    • 2019-12-01
    相关资源
    最近更新 更多