Nuraiz
Nuraiz

Reputation: 1070

Draw and move animation from xml in android

What I want to do: I want to draw image from xml and then animate it from xml. this image should move with constant speed anywhere on our screen.

Now the problem is: I can draw and animate image from xml but i can not move this image with constant speed.

I am using two xml files: One for animate and other for moving. XML for animation: android:duration="200"/>

XML file for move:

<translate
    android:interpolator="@android:anim/linear_interpolator"
    android:fromXDelta="2%"
    android:toXDelta="400%"
    android:fromYDelta="2%"
    android:toYDelta="800%"/>

Activity.java file code in onCreate() method:

  ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
  Animation hyperspaceJump = AnimationUtils.loadAnimation(this,   R.anim.hyperspace_jump);      
  rocketImage.setBackgroundResource(R.drawable.rocket_thrust);
  AnimationDrawable rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
  rocketAnimation.start();
  rocketImage.startAnimation(hyperspaceJump);

Upvotes: 1

Views: 2232

Answers (1)

Will Kru
Will Kru

Reputation: 5222

From the manpages I understand you shouldn't be using percentages in those properties, but coordinates.

http://developer.android.com/reference/android/view/animation/TranslateAnimation.html#TranslateAnimation%28float,%20float,%20float,%20float%29

Upvotes: 1

Related Questions