Daisy-like dialog used in Android projects
One:
Two used in the project:
1. First define the animation file
<?xml version= "1.0" encoding= "Utf-8"? ><animated-rotate xmlns:android= "Http://schemas.android.com/apk/res /android " android:drawable=" @drawable/loading2 " android:fromdegrees=" 0.0 " android:pivotx=" 50% " android:pivoty= "50.0%" android:todegrees= "360.0"/>
2. Define the ProgressBar directly in the Main.xml file to display
<?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:o rientation= "vertical" android:gravity= "center" > <progressbar android:id= "@+id/progress " Style= "? Android:attr/progressbarstylesmall" android:layout_width= "25dip" android:layout_height= "30dip" android:indeterminatedrawable= "@anim/progress_bar"/></linearlayout>
The effect after running directly is as shown in one!
However, it is not possible to use the convenience in the project, every need to use this dialog need to define the ProgressBar control in the corresponding XML file, if the development of the interface using multi-level framelayout and multi-level layout, this is a troublesome problem.
The ProgressBar is defined separately as an XML, and is dynamically added to the layout by defining a separate method . it can be called from the entire application using the activity initialization of the base class directly.
The first step:
- Define a separate layout_loading_dialog.xml File
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:id=" @+id/dialog_view " android:layout_width=" match_parent " android:layout_height=" Match_parent " android:background=" @android: color/transparent " android:gravity=" Center_vertical|center " > <progressbar style= "? Android:attr/progressbarstylesmall" android:layout_width= "25dip " android:layout_height= "30dip" android:indeterminatedrawable= "@anim/progress_bar"/></linearlayout>
Note:Here, add the android:background= "@android: Color/transparent" property to the parent layout to make the layout transparent.
Step Two:
- Define method Load Create Dialog
/** * Create custom ProgressDialog * * @param context * @return */public static Dialog Createloadingdialog (Context context) { Layoutinflater Inflater = layoutinflater.from (context); View v = inflater.inflate (r.layout.layout_loading_dialog, NULL); Get load View linearlayout layout = (linearlayout) V.findviewbyid (R.id.dialog_view);//Load Layout Dialog Loadingdialog = new Dialog (context, r.style.loading_dialog); Create a custom Style dialog loadingdialog.setcancelable (false);//You may not use the "Return key" to cancel the Loadingdialog.setcontentview (layout , New Linearlayout.layoutparams ( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); return loadingdialog; }
Step Three:
- Initialize in the Baseactiviy of the base class at the time of invocation, and then call Mloading.show () directly in the callback method that begins the request data
Baseactivity
Package Org.gaochun.ui;import android.app.activity;import Android.app.dialog;import android.os.bundle;/** * @author Gao_chun * This class is the activity base class */public class Baseactivity extends activity {public static final String TAG = "Gao_chun";
//initializes the Dialog public Dialog mloading in the base class ; /* (Non-javadoc) * @see android.app.activity#oncreate (android.os.Bundle) */ @Override protected void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); /*if (! Validateutils.isnetworkavailable (This)) { dialogutils.showtoast (this,r.string.text_network_unavailable); } * /mloading = Dialogutils.createloadingdialog (this);} }
Mainactivity
Package Org.gaochun.ui;import Android.os.bundle;import Org.gaochun.r;public class Mainactivity extends BaseActivity { c0/> @Override protected void onCreate (Bundle savedinstancestate) { //TODO auto-generated method stub Super.oncreate (savedinstancestate); Setupviews (); } private void Setupviews () { setcontentview (r.layout.main); /**************************************** * Only call the show () method here * Note: can be called in the callback method at the beginning of access to the network * After the end of the access Mloading.dismiss (); / mloading.show (); }}
source Download:http://download.csdn.net/download/gao_chun/8631127
Reprint please indicate the source.
Daisy-like dialog used in Android projects