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
- <? XML version= "1.0" encoding="Utf-8"?>
- <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/dialog_view"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:minheight="60DP"
- android:minwidth="180DP"
- android:gravity="center"
- android:padding="10DP"
- android:background="@drawable/loading_bg">
- <ImageView
- android:id="@+id/img"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/publicloading"
- />
- <TextView
- android:id="@+id/tiptextview"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginleft="10DP"
- android:text="Data Loading ..." />
- </linearlayout>
3. Define a Loadingdialog ImageView rotation animation: loading_animation.xml
[HTML]View Plaincopy
- <? 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=" "
- android:startoffset="-1"
- android:repeatmode="Restart"
- android:repeatcount="-1"/>
- </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