Imitation MOOC pull-down animation, imitation MOOC pull-down loading

Source: Internet
Author: User

Imitation MOOC pull-down animation, imitation MOOC pull-down loading

Recently, I read a post on eoe in my animation project. Then I tried to load the animation on the imitation MOOC network.

After all, the source code is not included in the post I saw. So I used the ps label myself. After implementation, it was actually quite simple, that is, the imationdrawable class is used to traverse the picture of items in the Animation-list, similar to frame Animation in flash.

Next, we will first attach the source code, which is easy to understand:

In order to make the animation effect reusable, It inherits the ImageView to implement some methods.

1 package com. example. loading_drawable; 2 3 import android. content. context; 4 import android. graphics. drawable. animationDrawable; 5 import android. util. attributeSet; 6 import android. util. log; 7 import android. view. view; 8 import android. view. animation. animation; 9 import android. widget. imageView; 10 11 public class MyImgView extends ImageView {12 // animation layer class 13 private AnimationDrawable bg_anim; 14 15 p Ublic MyImgView (Context context) {16 super (context, null); 17 initView (); 18} 19 20 public MyImgView (Context context, AttributeSet attrs) {21 super (context, attrs, 0); 22} 23 24 public MyImgView (Context context, AttributeSet attrs, int defStyle) {25 super (context, attrs, defStyle ); 26 27} 28 // initialize 29 private void initView () {30 setBackgroundResource (R. drawable. flash_anim); 31 bg_anim = (AnimationDrawabl E) getBackground (); 32 Log. I ("AAA", "iniView"); 33} 34 35/** 36 * enable animation effect 37 */38 public void startAnim () {39 if (bg_anim! = Null) {40 bg_anim.start (); 41} 42} 43 44/** 45 * Stop animation effect 46 */47 public void stopAnim () {48 if (bg_anim! = Null & bg_anim.isRunning () {49 bg_anim.stop (); 50} 51} 52 53/* 54 * (non-Javadoc) 55*56 * @ see android. widget. imageView # setVisibility (int) Enable the animation effect when the control is displayed. Otherwise, 57 */58 @ Override59 public void setVisibility (int visibility) {60 super. setVisibility (visibility); 61 if (visibility = View. VISIBLE) {62 startAnim (); 63} else {64 stopAnim (); 65} 66} 67 68}

 

Next, create the drawable folder under the res folder, and then create the flash_anim.xml file under the folder, as shown below:

 1 <?xml version="1.0" encoding="utf-8"?> 2 <animation-list xmlns:android="http://schemas.android.com/apk/res/android" 3     android:oneshot="false"> 4     <item android:drawable="@drawable/a01_02" android:duration="50"/> 5       <item android:drawable="@drawable/a01_04" android:duration="50"/> 6       <item android:drawable="@drawable/a01_06" android:duration="50"/> 7       <item android:drawable="@drawable/a01_08" android:duration="50"/> 8       <item android:drawable="@drawable/a01_10" android:duration="50"/> 9       <item android:drawable="@drawable/a01_12" android:duration="50"/>10       <item android:drawable="@drawable/a01_14" android:duration="50"/>11       <item android:drawable="@drawable/a01_16" android:duration="50"/>12       <item android:drawable="@drawable/a01_25" android:duration="50"/>13       <item android:drawable="@drawable/a01_26" android:duration="50"/>14       <item android:drawable="@drawable/a01_27" android:duration="50"/>15       <item android:drawable="@drawable/a01_28" android:duration="50"/>16       <item android:drawable="@drawable/a01_30" android:duration="50"/>17       <item android:drawable="@drawable/a01_31" android:duration="50"/>18       <item android:drawable="@drawable/a01_32" android:duration="50"/>19       <item android:drawable="@drawable/a01_41" android:duration="50"/>20       <item android:drawable="@drawable/a01_42" android:duration="50"/>21       <item android:drawable="@drawable/a01_43" android:duration="50"/>22       <item android:drawable="@drawable/a01_44" android:duration="50"/>23       <item android:drawable="@drawable/a01_45" android:duration="50"/>24       <item android:drawable="@drawable/a01_46" android:duration="50"/>25       <item android:drawable="@drawable/a01_47" android:duration="50"/>26       <item android:drawable="@drawable/a01_48" android:duration="50"/>27       <item android:drawable="@drawable/a01_57" android:duration="50"/>28       <item android:drawable="@drawable/a01_58" android:duration="50"/>29       <item android:drawable="@drawable/a01_59" android:duration="50"/>30       <item android:drawable="@drawable/a01_60" android:duration="50"/>31       <item android:drawable="@drawable/a01_61" android:duration="50"/>32       <item android:drawable="@drawable/a01_62" android:duration="50"/>33       <item android:drawable="@drawable/a01_63" android:duration="50"/>34       <item android:drawable="@drawable/a01_64" android:duration="50"/>35 </animation-list>

In this way, the user-defined main can be called in main as follows:

1 package com. example. loading_drawable; 2 3 import android. app. activity; 4 import android. OS. bundle; 5 import android. view. gravity; 6 import android. view. view; 7 import android. view. view. onClickListener; 8 import android. widget. button; 9 import android. widget. linearLayout; 10 import android. widget. linearLayout. layoutParams; 11 12/** 13 * @ author Administrator MOOC pull-down refresh progress display control 14*15 */16 public class MainActivity extends Activity {17 @ Override18 protected void onCreate (Bundle savedInstanceState) {19 super. onCreate (savedInstanceState); 20 LinearLayout rootLayout = new LinearLayout (this); 21 rootLayout. setOrientation (LinearLayout. VERTICAL); 22 rootLayout. setLayoutParams (new LinearLayout. layoutParams (23 LinearLayout. layoutParams. MATCH_PARENT, 24 LinearLayout. layoutParams. MATCH_PARENT); 25 rootLayout. setGravity (Gravity. CENTER); 26 27 Button btn = new Button (this); 28 btn. setText ("show animation"); 29 30 final MyImgView imgView = new MyImgView (MainActivity. this); 31 imgView. setLayoutParams (new LinearLayout. layoutParams (32 LinearLayout. layoutParams. WRAP_CONTENT, 33 LinearLayout. layoutParams. WRAP_CONTENT); 34 imgView. setVisibility (View. GONE); 35 36 rootLayout. addView (btn); 37 rootLayout. addView (imgView); 38 39 setContentView (rootLayout); 40 41 btn. setOnClickListener (new OnClickListener () {42 43 @ Override44 public void onClick (View arg0) {45 imgView. setVisibility (View. VISIBLE); 46} 47}); 48} 49}

Here we use custom code to layout files. This personal hobby is also a project requirement. You can also understand the custom code layout, which facilitates the integration of plug-in code;

As mentioned above, this animation is complete. You only need to set imgview to display as needed, the animation will be turned on, and the hidden animation will be closed.

 

 

For your convenience, add the code and icons, but the icons are not doing well.

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.