Draw and move animation from xml in android
- by Muahammad Yousuf Saif
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);