English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This article describes an Android animation formed by playing multiple images. Shared for everyone's reference, as follows:
In Android, images can be played frame by frame to produce a dynamic effect. Prepare several consecutive images, then create an anim folder under the res folder of the source program, and then create a new XML file.
The following is the XML code:
<?xml version="1.0" encoding="utf-8"?>; <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"> <item android:drawable="@drawable/c1" android:duration="200" /> <item android:drawable="@drawable/c2" android:duration="200" /> <item android:drawable="@drawable/c3" android:duration="200" /> <item android:drawable="@drawable/c4" android:duration="200" /> <item android:drawable="@drawable/c5" android:duration="200" /> <item android:drawable="@drawable/c6" android:duration="200" /> </animation-list>
Among which c1,c2,c3,c4,c5,c6Is the name of the image added.
Place an ImageView control inside the window and write the code in it:
_imageView1 =(ImageView) findViewById(R.id.imageView1);//Placement of the ImageView control //Set the animation background _imageView1.setBackgroundResource(R.anim.animation_list);//Among them, R.anim.animation_list is the resource name of the animation description file prepared in the previous step //Get the animation object _animaition = (AnimationDrawable)_imageView1.getBackground();
Finally, you can start the animation, the code is as follows:
//Is it just to start once? _animaition.setOneShot(false); if(_animaition.isRunning())//Is it running? { _animaition.stop();//Stop } _animaition.start();//Start
Readers who are interested in more content related to Android can check the special topics on this site: 'Summary of Android Graphics and Image Processing Techniques', 'Android Development Tutorial for Beginners and Advanced', 'Summary of Android Debugging Techniques and Common Problem Solutions', 'Summary of Android Multimedia Operation Techniques (audio, video, recording, etc.)', 'Summary of Android Basic Component Usage', 'Summary of Android View View Techniques', 'Summary of Android Layout Layout Techniques', and 'Summary of Android Widget Usage'
I hope this article will be helpful to everyone in Android program design.
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to notice#w3Please send an email to codebox.com (replace # with @ when sending an email) to report any infringement, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.