How can I create moving image in an android application
how can i create a moving image object for an android game application.and also how can i add animation to the resources
plz tell me 开发者_如何学JAVAwhat is the correct or better way to do that
thanks in advance
-Kariyachan
See the Android documentation on 2d Graphics, especially about "Tween" and "Frame" Animations.
One of the ways in which android application developer can add moving images like those in GIF Format is by using AnimationDrawable class which is under the package “android.graphics.drawable.AnimationDrawable”.This class uses multiple images as frames and displays them with particular animation which can be set using the class functions.
Firstly,the package needs to be imported and in the \res\drawable folder the images have to be copied which are to be displayed or animated.
Secondly,the images needs to be converted to Bitmap
using BitmapDrawable
class which is under the package “android.graphics.drawable.BitmapDrawable” .The images are converted as shown below:
BitmapDrawable frame1=(BitmapDrawable)getResources().getDrawable(R.drawable.w1);
where w1 is the name of the image in\res\drawable folder.
Thirdly,these Bitmap images have to be added to the animation.
The addFrame(Drawable frame,int duration) function is used to add frames(images) to the animation.The two parameters frame and duration are Bitamap image(frame) and the time in milliseconds for which the frame(image) should appear.The function setOmeShot(boolean)
is used to set whether animation is to be played once or repeat.Pass true if the animation should only play once otherwise false.
Fourthly, the animation has to be set to the ImageView.
Lastly the animation has to be started.
animation.start();
//For full post with sample code you can visit post on my website
精彩评论