Android Combat Simple Tutorial-the 56th gun (simulation of the American Group client Progress prompt box)

Source: Internet
Author: User

Friends of the United States have used the client know, the United States the load waiting prompt is very interesting, is a form of animation to show us, the following we will understand the principle behind this, and then achieve their own wait animation effect.

First we prepare two pictures:


Do these two pictures look exactly the same? Careful friends will find the only difference in the foot, OK, we use the rotation of the two images to achieve animation effect, the following look at the code:

1. Animation file Frame_meituan.xml:

<?xml version= "1.0" encoding= "Utf-8"? ><animation-list xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:oneshot=" false ">    <item        android:drawable=" @drawable/progress_loading_image_ "android:duration=" "        />    <item        android:drawable=" @drawable/progress_loading_image_02 "        android:duration= "/></animation-list>"

150 milliseconds to toggle the picture, simulate the animation effect.

2. Simply customize a control-meituanprogressdialog.java:

Package Com.finddreams.runningman;import Android.app.progressdialog;import Android.content.context;import Android.graphics.drawable.animationdrawable;import Android.os.bundle;import Android.widget.imageview;import Android.widget.textview;import com.example.runningman.r;/** * @Description: Customize dialog box * @author http://blog.csdn.net/ yayun0516 */public class Meituanprogressdialog extends ProgressDialog {private animationdrawable manimation;private Context mcontext;private ImageView mimageview;private String mloadingtip;private TextView mloadingtv;private int count =            0;private String oldloadingtip;private int mresid;/** * * @param context * Context Object * @param content * Display text message content * @param ID * Animation ID */public meituanprogressdialog (context context, String content, int id) {Super (C Ontext); this.mcontext = Context;this.mloadingtip = Content;this.mresid = Id;setcanceledontouchoutside (true);} @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (SavedinStancestate); Initview (); InitData ();} private void InitData () {mimageview.setbackgroundresource (MRESID);// Animationdrawablemanimation = (animationdrawable) mimageview.getbackground () of the background display through the ImageView object; Mimageview.post ( New Runnable () {@Overridepublic void run () {Manimation.start ();}}); Mloadingtv.settext (Mloadingtip);} public void SetContent (String str) {mloadingtv.settext (str);} private void Initview () {Setcontentview (R.layout.progress_dialog);//Display Interface MLOADINGTV = (TextView) Findviewbyid ( R.ID.LOADINGTV); Mimageview = (ImageView) Findviewbyid (R.ID.LOADINGIV);}}

The progress_dialog.xml of the hint layout file used above:

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" wrap_content "    android:layout_height=" wrap_content "   android:layout_ gravity= "center"    android:orientation= "vertical" >    <imageview        android:id= "@+id/loadingiv"        Android:layout_width= "Wrap_content"        android:layout_height= "wrap_content"        android:background= "@anim/ Frame_meituan "/>    <textview        android:id=" @+id/loadingtv "android:layout_width=" Wrap_content        "        android:layout_height=" wrap_content "android:layout_alignbottom=" @+id/loadingiv "Android:layout_ Centerhorizontal= "true" android:textsize= "20sp"        android:text= "Loading in:"/></relativelayout>

finally called in the activity:

Package Com.finddreams.runningman;import Com.example.runningman.r;import Android.app.activity;import Android.os.bundle;import android.os.handler;import android.view.view;/** * @Description: Run the villain's Animation progress bar dialog box, can be used as loading data interface * @ Author http://blog.csdn.net/yayun0516 */public class Meituanmanactivity extends Activity {private Meituanprogressdialog dialog; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.meituan_progressdialog);} /** * Show US Team progress dialog box * @param v */public void Showmeidialog (View v) {dialog =new Meituanprogressdialog (this, "Loading in", R.anim.fram E_meituan);d ialog.show (); Handler Handler =new Handler () handler.postdelayed (new Runnable () {@Overridepublic void run () {Dialog.dismiss ();}, 3000);//3 seconds after calling the dismiss method to hide;}}

Finally, let's get our program up and running:


OK, run up and you want to join your project, just prepare two pictures to replace them to simulate the animation.

SOURCE Free Download

Finally pay attention to me Bai, thank you!


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Combat Simple Tutorial-the 56th gun (simulation of the American Group client Progress prompt box)

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.