Android development path-simple animation

Source: Internet
Author: User
Document directory
  • Simple Animation:
  • Put images in the drawable directory,
  • Create an xml file frame. xml and save the image as follows:
  • Then define a layout frame_layout.xml:
  • Then write the activity class, FrameActivity. java:
  • At this point, you can run and implement it after registering in the list.
Simple Animation: add images to the drawable directory,

Create an xml file frame. xml and save the image as follows:
<? Xml version = "1.0" encoding = "UTF-8"?> <Animation-list xmlns: android = "http://schemas.android.com/apk/res/android" android: oneshot = "false"> <! -- Can be added repeatedly to implement loop --> <! -- Android: duration = "100" sets the duration of the image --> <item android: drawable = "@ drawable/girl_1" android: duration = "100"/> <item android: drawable = "@ drawable/girl_2" android: duration = "100"/> <item android: drawable = "@ drawable/girl_3" android: duration = "100"/> <item android: drawable = "@ drawable/girl_4" android: duration = "100"/> <item android: drawable = "@ drawable/girl_5" android: duration = "100"/> <item android: drawable = "@ drawable/girl_6" android: duration = "200"/> <item android: drawable = "@ drawable/girl_7" android: duration = "300"/> <item android: drawable = "@ drawable/girl_6" android: duration = "200"/> <item android: drawable = "@ drawable/girl_7" android: duration = "300"/> <item android: drawable = "@ drawable/girl_8" android: duration = "200"/> <item android: drawable = "@ drawable/girl_9" android: duration = "100"/> <item android: drawable = "@ drawable/girl_10" android: duration = "100"/> <item android: drawable = "@ drawable/girl_11" android: duration = "100"/> </animation-list>

Then define a layout frame_layout.xml:
<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical" android: gravity = "center"> <! -- Bearer image --> <ImageView android: id = "@ + id/frameIV" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> </LinearLayout>

 

Then write the activity class, FrameActivity. java:
Package cn. class3g. animation; import android. app. activity; import android. graphics. drawable. animationDrawable; import android. OS. bundle; import android. view. motionEvent; import android. widget. imageView; public class FrameActivity extends Activity {AnimationDrawable attackAnimation; // define the animation object ImageView frameIV; protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); this. setContentView (R. layout. frame_layout); init ();} private void init () {frameIV = (ImageView) this. findViewById (R. id. frameIV); frameIV. setBackgroundResource (R. drawable. frame); // get the image and add it to the layout (as a background image) attackAnimation = (AnimationDrawable) frameIV. getBackground (); // get the background image to the animation object} // trigger public boolean onTouchEvent (MotionEvent event) {if (event. getAction () = MotionEvent. ACTION_DOWN) {attackAnimation. start (); // click the screen to start the animation} return super. onTouchEvent (event );}}

 

At this point, you can run and implement it after registering in the list.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.