Draw and move animation from xml in android
Posted
by
Muahammad Yousuf Saif
on Stack Overflow
See other posts from Stack Overflow
or by Muahammad Yousuf Saif
Published on 2010-12-22T11:51:29Z
Indexed on
2010/12/22
11:54 UTC
Read the original article
Hit count: 277
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);
© Stack Overflow or respective owner