Animate image along path on Android? [duplicate]

2019-02-26 07:11发布

Possible Duplicate:
Android, move bitmap along a path?

Is there a way to animate an ImageView's position along a path on the Android as with a CGPath on the iPhone? I have scoured the web for a solution to this, but no one has even seemed to ask about it. I didn't see anything in the Android docs describing this functionality.

2条回答
你好瞎i
2楼-- · 2019-02-26 07:42

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

查看更多
干净又极端
3楼-- · 2019-02-26 07:45

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

查看更多
登录 后发表回答