SoFunction
Updated on 2025-03-01

Android implements imitation of MOOC download and loading animation

I won't introduce the specific implementation method. I will attach the source code first. I believe everyone can easily understand it:

In order to make this animation effect reusable, we inherited ImageView to implement certain methods.

 

package .loading_drawable;

import ;
import ;
import ;
import ;
import ;
import ;
import ;

public class MyImgView extends ImageView {
// Animation layer classprivate AnimationDrawable bg_anim;

public MyImgView(Context context) {
super(context, null);
initView();
}

public MyImgView(Context context, AttributeSet attrs) {
super(context, attrs, 0);
}

public MyImgView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

}
//initializationprivate void initView() {
setBackgroundResource(.flash_anim);
bg_anim = (AnimationDrawable) getBackground();
("AAA", "iniView");
}

/**
 * Start the startup effect
 */
public void startAnim() {
if (bg_anim != null) {
 bg_anim.start();
}
}

/**
 * Stop animation effect
 */
public void stopAnim() {
if (bg_anim != null && bg_anim.isRunning()) {
 bg_anim.stop();
}
}

/*
 * (non-Javadoc)
 *
 * @see #setVisibility(int) Called when the control is displayed. Turn on the startup effect, otherwise
 */
@Override
public void setVisibility(int visibility) {
(visibility);
if (visibility == ) {
 startAnim();
} else {
 stopAnim();
}
}

}

Next is: create a new drawable folder under the res folder, and then create a new flash_anim.xml file under this folder. The details are as follows:

 

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:andro
android:oneshot="false">
<item android:drawable="@drawable/a01_02" android:duration="50"/>
<item android:drawable="@drawable/a01_04" android:duration="50"/>
<item android:drawable="@drawable/a01_06" android:duration="50"/>
<item android:drawable="@drawable/a01_08" android:duration="50"/>
<item android:drawable="@drawable/a01_10" android:duration="50"/>
<item android:drawable="@drawable/a01_12" android:duration="50"/>
<item android:drawable="@drawable/a01_14" android:duration="50"/>
<item android:drawable="@drawable/a01_16" android:duration="50"/>
<item android:drawable="@drawable/a01_25" android:duration="50"/>
<item android:drawable="@drawable/a01_26" android:duration="50"/>
<item android:drawable="@drawable/a01_27" android:duration="50"/>
<item android:drawable="@drawable/a01_28" android:duration="50"/>
<item android:drawable="@drawable/a01_30" android:duration="50"/>
<item android:drawable="@drawable/a01_31" android:duration="50"/>
<item android:drawable="@drawable/a01_32" android:duration="50"/>
<item android:drawable="@drawable/a01_41" android:duration="50"/>
<item android:drawable="@drawable/a01_42" android:duration="50"/>
<item android:drawable="@drawable/a01_43" android:duration="50"/>
<item android:drawable="@drawable/a01_44" android:duration="50"/>
<item android:drawable="@drawable/a01_45" android:duration="50"/>
<item android:drawable="@drawable/a01_46" android:duration="50"/>
<item android:drawable="@drawable/a01_47" android:duration="50"/>
<item android:drawable="@drawable/a01_48" android:duration="50"/>
<item android:drawable="@drawable/a01_57" android:duration="50"/>
<item android:drawable="@drawable/a01_58" android:duration="50"/>
<item android:drawable="@drawable/a01_59" android:duration="50"/>
<item android:drawable="@drawable/a01_60" android:duration="50"/>
<item android:drawable="@drawable/a01_61" android:duration="50"/>
<item android:drawable="@drawable/a01_62" android:duration="50"/>
<item android:drawable="@drawable/a01_63" android:duration="50"/>
<item android:drawable="@drawable/a01_64" android:duration="50"/>
</animation-list>

This is basically done. Next, you need to call the customized main in main; as follows:

package .loading_drawable;

import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;

/**
 * @author Administrator MOOC drop-down refresh progress display control
 *
 */
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
 (savedInstanceState);
 LinearLayout rootLayout = new LinearLayout(this);
 ();
 (new (
   .MATCH_PARENT,
   .MATCH_PARENT));
 ();

 Button btn = new Button(this);
 ("Show animation");

 final MyImgView imgView = new MyImgView();
 (new (
   .WRAP_CONTENT,
   .WRAP_CONTENT));
 ();

 (btn);
 (imgView);

 setContentView(rootLayout);

 (new OnClickListener() {

  @Override
  public void onClick(View arg0) {
   ();
  }
 });
}
}

This is done with custom code layout files, which are easy to layout and integrate plug-in code. As mentioned above, this animation is completed. Only set imgview to display where necessary, the animation will be turned on and the hidden animation will be turned off.

The specific content is over here, I hope everyone likes it.