Android Custom-like ProgressDialog effect dialog

Source: Internet
Author: User

Android customizes dialog similar to the ProgressDialog effect.

Here's how:

1. First prepare two pictures and background images (or not backgrounds) that you want to define as the effect.

As I want the effect:

2. Define the Loading_dialog.xml layout file (Here you can also define your own layout effect, the key is to have a imageview):

[HTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/dialog_view"
  4. android:orientation="vertical"
  5. android:layout_width="fill_parent"
  6. android:layout_height="fill_parent"
  7. android:minheight="60DP"
  8. android:minwidth="180DP"
  9. android:gravity="center"
  10. android:padding="10DP"
  11. android:background="@drawable/loading_bg">
  12. <ImageView
  13. android:id="@+id/img"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:src="@drawable/publicloading"
  17. />
  18. <TextView
  19. android:id="@+id/tiptextview"
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:layout_marginleft="10DP"
  23. android:text="Data Loading ..." />
  24. </linearlayout>

3. Define a Loadingdialog ImageView rotation animation: loading_animation.xml

[HTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <set android:shareinterpolator="false" xmlns:android= "http://schemas.android.com/apk/res/ Android ">
  3. <rotate
  4. android:interpolator="@android: Anim/linear_interpolator"
  5. android:pivotx="50%"
  6. android:pivoty="50%"
  7. android:fromdegrees="0"
  8. android:todegrees="+360"
  9. android:duration=" "
  10. android:startoffset="-1"
  11. android:repeatmode="Restart"
  12. android:repeatcount="-1"/>
  13. </Set>

4. Define the style of the dialog.

<!--Custom Loading Dialog -      <stylename= "Loading_dialog"Parent= "Android:style/theme.dialog">          <Itemname= "Android:windowframe">@null</Item>          <Itemname= "Android:windownotitle">True</Item>           <Itemname= "Android:windowbackground">@drawable/LOADING_BG</Item>          <Itemname= "Android:windowisfloating">True</Item>          <Itemname= "Android:windowcontentoverlay">@null</Item>      </style>  

[Java]View Plaincopy

5. Write the code that creates dialog, and you can encapsulate it yourself as a method.

/*** Get Customized ProgressDialog *@paramContext *@parammsg *@return      */       Public StaticDialog Createloadingdialog (context context, String msg) {layoutinflater Inflater=Layoutinflater.from (context); View v= Inflater.inflate (R.layout.loading_dialog,NULL);//Get load ViewLinearLayout layout = (linearlayout) V.findviewbyid (R.id.dialog_view);//Loading Layouts//the ImageView in Main.xmlImageView Spaceshipimage =(ImageView) V.findviewbyid (r.id.img); TextView Tiptextview= (TextView) V.findviewbyid (R.id.tiptextview);//hint Text//Loading AnimationsAnimation hyperspacejumpanimation =animationutils.loadanimation (context, r.anim.load_animation); //display animations using ImageViewspaceshipimage.startanimation (hyperspacejumpanimation); Tiptextview.settext (msg);//Setting Load InformationDialog Loadingdialog=NewDialog (context, r.style.loading_dialog);//Create a custom style dialogloadingdialog.setcancelable (false);//can not be canceled with "Return key"Loadingdialog.setcontentview (Layout,Newlinearlayout.layoutparams (LinearLayout.LayoutParams.FILL_PARENT, Linearlayout.layo utparams.fill_parent));//Set Layout        returnLoadingdialog; }  


The last one to come in whole:

--------------------------------------------------------------------------------------------------------------- ----------------------

The previous article wrote the use of the system ProgressBar implementation of a slightly good-looking progressdialog, if you want your own progressdialog more own style, then use the picture to achieve, will achieve your goal. Words do not say, first look at the effect: After reading the article, the realization of this is very simple, just need to put the layout of the file ProgressBar ImageView on it.

After switching to ImageView, we need to make this imageview move, which requires a anim process.

The realization idea is: uses an animation to replace ImageView's picture resource, then lets the animation move up is OK.

Use this resource as a background image of ImageView

 <?XML version= "1.0" encoding= "Utf-8"?>  <animation-listxmlns:android= "Http://schemas.android.com/apk/res/android"Android:oneshot= "false">      <Itemandroid:drawable= "@drawable/icon_loading1"android:duration= "+"/>      <Itemandroid:drawable= "@drawable/icon_loading2"android:duration= "+"/>      <Itemandroid:drawable= "@drawable/icon_loading3"android:duration= "+"/>      <Itemandroid:drawable= "@drawable/icon_loading4"android:duration= "+"/>      <Itemandroid:drawable= "@drawable/icon_loading5"android:duration= "+"/>      <Itemandroid:drawable= "@drawable/icon_loading6"android:duration= "+"/>      <Itemandroid:drawable= "@drawable/icon_loading7"android:duration= "+"/>      <Itemandroid:drawable= "@drawable/icon_loading8"android:duration= "+"/>  </animation-list>  

And then we're going to start the animation in the Myprogressdialog class.

ImageView ImageView = (ImageView) Progressdialog.findviewbyid (r.id.loadimg);           = (animationdrawable) imageview.getbackground ();          Animationdrawable.start ();  


Complete these and then you can call our Myprogressdialog in the activity.

For convenience, I enclose my picture resources, hoping to be able to use

    • Previous Android Custom ProgressDialog using System ProgressBar and picture implementation (a) system ProgressBar next Android Popupwindow with ListView
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.