开发者

Animate image along path on Android? [duplicate]

This question already has answers here: 开发者_运维百科 Closed 10 years ago.

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜