2

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.

Community
  • 1
  • 1
Jacob
  • 926
  • 1
  • 14
  • 25
  • I know this is rather old, but for anyone else looking for help, take a look here: http://stackoverflow.com/questions/6849554/problem-to-achieve-curved-animation/8454990#8454990 – Sam Judd Dec 10 '11 at 07:05

2 Answers2

4

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

coocood
  • 1,376
  • 11
  • 8
0

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

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • Thanks for the response. However, that is animation along a straight line. I would like to animate along a curved path. – Jacob Feb 18 '11 at 06:53