Animate image along path on Android? [duplicate]

六眼飞鱼酱① 提交于 2019-12-02 02:21:26

I created a subclass of Animation named PathAnimation, which can animate along a path.

You can just create a new PathAnimation with a Path, and use it like any other Animations.

https://github.com/coocood/PathAnimation

You are going to want to use an Animation resource. Here is a sample one that will slide view in from the left. You'd put something like this into an xml file in your projects res/anim folder.

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

Then to use it from the java code you are going to do something like this:

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

This particular example is using the overshoot_interpolator which will make the view that its applied to go past its target and then bounce back. For more info about different interpolaters, and using Animation resources check out the documentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!