Custom progressdialog to improve user experience and progressdialog

Source: Internet
Author: User

Custom progressdialog to improve user experience and progressdialog
Custom progressdialog to improve user experience


:



Specific implementation methods:

1. Define the Layout of Dialog

2. Set the animation anim

3. Create a custom dialog Style

4. Create a common method to control the Dialog


1. Define the Layout layout of Dialog: layout_loading_dialog.xml in the Layout directory

<?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:gravity="center_vertical|center"    android:orientation="vertical"    android:background="@color/transparent">    <ImageView        android:id="@+id/img"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/loading" /></LinearLayout>


2. Set the animation anim: Create the anim directory loading_animation.xml

<?xml version="1.0" encoding="utf-8"?><set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android">    <rotate         android:interpolator="@android:anim/linear_interpolator"        android:pivotX="50%"        android:pivotY="50%"        android:fromDegrees="0"        android:toDegrees="+360"        android:duration="1500"        android:startOffset="-1"        android:repeatMode="restart"        android:repeatCount="-1"/></set>



3. Create a custom dialog style Theme: values directory themes. xml

<! -- Customize loading dialog --> <style name = "loading_dialog" parent = "android: Theme. dialog "> <item name =" android: windowFrame "> @ null </item> <! -- The windowFrame box of Dialog is none --> <item name = "android: windowBackground"> @ color/transparent </item> <! -- Set the dialog background --> <item name = "android: windowNoTitle"> true </item> <! -- Whether to display title --> <item name = "android: javaswistranslucent"> true </item> <! -- Translucent? --> <item name = "android: javaswisfloating"> true </item> <! -- Whether to float above activity --> <item name = "android: windowContentOverlay"> @ null </item> <! -- It is also a drawable that defines the background of contentoverlay --> <item name = "android: backgroundDimEnabled"> false </item> <! -- Whether the background is blurred --> </style>


4. Create a common method to control the Dialog

/*** Get the 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); // obtain the value of loading view LinearLayout = (LinearLayout) v. findViewById (R. id. dialog_view); // load the layout ImageView spaceshipImage = (ImageView) v. findViewById (R. id. img); Animation hyperspaceJumpAnimation = AnimationUtils. loadAnimation (context, R. anim. loading_animation); // load the animation spaceshipImage. startAnimation (hyperspaceJumpAnimation); // use ImageView to display the animation Dialog loadingDialog = new Dialog (context, R. style. loading_dialog); // create a custom Style dialog // loadingDialog. setCancelable (false); // The "Return key" cannot be used to cancel loadingDialog. setContentView (layout, new LinearLayout. layoutParams (LinearLayout. layoutParams. WRAP_CONTENT, LinearLayout. layoutParams. WRAP_CONTENT); return loadingDialog ;}



OK! You can directly call it when using it: public Dialog mLoading; mLoading = DialogUtils. createLoadingDialog (this); mLoading. show (); mLoading. dismiss ();



Customize ProgressDialog size and circle display position

ProgressDialog dialog;
Dialog. getWindow (). setGravity (Gravity. BOTTOM );
 
Why do not call progressDialog in dialog in android to load progressDialog simultaneously?

What do you want to say?
// ProgressDialog = ProgressDialog. show (daoru. this, "Loading...", "Please wait ...");
InitProgressDialog ();
Do these two sentences need not be used at the same time?
If you are asking this question, the answer is simple, because the two are the same and there is no need to repeat them. They both display a prompt box and enable the thread to load contacts.

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.