Android custom View-animated Dialog

Source: Internet
Author: User

MainActivity is as follows:

Package cc. testview1; import android. OS. bundle; import android. app. activity;/*** Demo Description: * Custom Dialog, which has an animation (rotation or frame animation) in Dialog) effect */public class MainActivity extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); // first --> rotate animation LoadingDialogFirst loadingDialogFirst = new LoadingDialogFirst (this, R. style. dialog); loadingDialogFirst. show (); // second --> frame Animation // LoadingDialogSecond loadingDialogSecond = new LoadingDialogSecond (this, R. style. dialog); // loadingDialogSecond. show ();}}


LoadingDialogFirst is as follows:

package cc.testview1;import android.app.Dialog;import android.content.Context;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.widget.ImageView;public class LoadingDialogFirst extends Dialog {    private ImageView  mLoadingImageView;    private Animation mLoadingAnimation;public LoadingDialogFirst(Context context, boolean cancelable,OnCancelListener cancelListener) {super(context, cancelable, cancelListener);}public LoadingDialogFirst(Context context, int theme) {super(context, theme);}public LoadingDialogFirst(Context context) {super(context);}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);View loadingView=LayoutInflater.from(getContext()).inflate(R.layout.loading, null);mLoadingImageView=(ImageView) loadingView.findViewById(R.id.loadingImageView);setContentView(loadingView);}@Overridepublic void show() {super.show();mLoadingAnimation=AnimationUtils.loadAnimation(getContext(), R.anim.loadinganimfirst);mLoadingImageView.startAnimation(mLoadingAnimation);}@Overridepublic void dismiss() {super.dismiss();mLoadingAnimation.cancel();}}

LoadingDialogSecond is as follows:

Package cc. testview1; import android. app. dialog; import android. content. context; import android. graphics. drawable. animationDrawable; import android. OS. bundle; import android. OS. handler; import android. view. layoutInflater; import android. view. view; import android. widget. imageView; public class extends Dialog {private ImageView mLoadingImageView; private AnimationDrawable listener; public listener (Context context, boolean cancelable, OnCancelListener cancelListener) {super (context, cancelable, cancelListener );} public LoadingDialogSecond (Context context, int theme) {super (context, theme);} public LoadingDialogSecond (Context context) {super (context);} @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); View loadingView = LayoutInflater. from (getContext ()). inflate (R. layout. loading, null); mLoadingImageView = (ImageView) loadingView. findViewById (R. id. loadingImageView); mLoadingImageView. setImageResource (R. anim. loadinganimsecond); setContentView (loadingView);} @ Overridepublic void show () {super. show (); // place the animation startup in Handler. otherwise, only the first image new Handler () {} is displayed (){}. postDelayed (new Runnable () {@ Overridepublic void run () {mLoadingAnimationDrawable = (AnimationDrawable) mLoadingImageView. getDrawable (); mLoadingAnimationDrawable. start () ;}}, 10) ;}@ Overridepublic void dismiss () {super. dismiss (); // The animation mLoadingAnimationDrawable = (AnimationDrawable) mLoadingImageView. getDrawable (); mLoadingAnimationDrawable. stop ();}}


Main. xml is as follows:

         
       
 


Loading. xml is as follows:

 
     
      
  
 


Loadinganimfirst. xml is as follows:

 
     
  
 


Loadinganimsecond. xml is as follows:

     
     
     
 


Zookeeper

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.