【问题标题】:Android - swipe and rotate animation of ImageView from right to leftAndroid - 从右到左滑动和旋转 ImageView 的动画
【发布时间】:2020-11-30 22:04:28
【问题描述】:
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="128dp"
    android:layout_marginStart="32dp"
    android:layout_marginTop="64dp"
    android:layout_marginEnd="32dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <ImageView
        android:id="@+id/swipe"
        android:layout_width="64dp"
        android:layout_height="64dp"
        android:layout_alignParentEnd="true"
        android:rotation="15"
        app:srcCompat="@drawable/ic_swipe"
        app:tint="#FFFFFF" />
</RelativeLayout>

如您所见,图像在 RelativeLayout 内对齐并旋转了 15

我希望它滑动到父级的左侧并在滑动时旋转到-15。

ImageView 是一只指向上方的手,因此它假设是从右向左滑动的动画

【问题讨论】:

    标签: android android-animation


    【解决方案1】:
    swipe.animate().rotationBy(-30).setDuration(1000).translationX(-64).setInterpolator(new AccelerateDecelerateInterpolator()).start();
    

    这只是我的想法,但类似的东西应该可以!可能需要调整 -64 值:)

    【讨论】:

    • 旋转有效,但我还需要图像在旋转时滑动到左侧:D 它应该与父级左对齐
    • 也许你可以给相对布局一个id,然后说translationX(relativeLayout.left);或者像我说的,调整-64直到它对齐
    • 啊,好吧,我不明白 translationX 代表什么,谢谢 :D
    • 没问题。是的,它只是左右移动视图(沿 X 轴)。 TranslationY 会上下移动它。 :)
    猜你喜欢
    • 2011-07-06
    • 2021-07-05
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 1970-01-01
    相关资源
    最近更新 更多