【问题标题】:Animate image along path on Android? [duplicate]在Android上沿路径动画图像? [复制]
【发布时间】:2011-06-29 11:18:40
【问题描述】:

可能重复:
Android, move bitmap along a path?

有没有办法像 iPhone 上的 CGPath 一样在 Android 上沿路径设置 ImageView 的位置?我已经在网上搜索了这个问题的解决方案,但似乎没有人问过这个问题。我在 Android 文档中没有看到任何描述此功能的内容。

【问题讨论】:

标签: android animation path imageview


【解决方案1】:

我创建了一个名为 PathAnimation 的 Animation 子类,它可以沿路径设置动画。

您可以使用 Path 创建一个新的 PathAnimation,并像使用任何其他动画一样使用它。

https://github.com/coocood/PathAnimation

【讨论】:

    【解决方案2】:

    您将要使用动画资源。这是一个示例,它将从左侧滑入视图。您可以将这样的内容放入项目 res/anim 文件夹中的 xml 文件中。

    <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/overshoot_interpolator">
    
        <translate android:fromXDelta="100%p" android:toXDelta="0%p" android:duration="700"/>
    
    
    </set>
    

    然后要从 java 代码中使用它,您将执行以下操作:

    Animation slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
    yourImageView.startAnimation(slideLeftIn);
    

    这个特殊的例子使用了 overshoot_interpolator,它会使得应用它的视图越过它的目标然后反弹回来。有关不同插值器和使用动画资源的更多信息check out the documentation

    【讨论】:

    • 感谢您的回复。但是,那是沿直线的动画。我想沿着弯曲的路径制作动画。
    猜你喜欢
    • 2018-11-06
    • 2013-04-29
    • 2013-11-29
    • 2011-08-20
    • 2011-05-26
    • 2018-02-18
    • 2021-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多