Animate image along path on Android? [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-04 04:50:20

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/5035669/animate-image-along-path-on-android

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