Android pop-up window with animation effect

Source: Internet
Author: User

Android pop-up window with animation effect
It usually takes a lot of time to load data on the network. At this time, the program often needs to write a pop-up window indicating that the data is being loaded. This article uses two methods to achieve the Dialog with animation effect: both frame animation implementation and GIF dynamic image implementation can achieve the animation effect.
First, frame animation implementation
To customize a Dialog, first check the layout file dialog_animation.xml.

     
      
   
  
 
ImageView is used to display animations, and TextView is used to prompt users that we are loading data.
Public static Dialog createAnimationDailog (final Context context) {final Dialog dialog = new Dialog (context, R. style. dialog); dialog. setContentView (R. layout. dialog_animation); ImageView animationView = (ImageView) dialog. findViewById (R. id. dialog_animation_img); animationView. setBackgroundResource (R. drawable. animation_dialog); AnimationDrawable animationDrawable = (AnimationDrawable) animationView. getBackground (); animationDrawable. start (); final TextView textView = (TextView) dialog. findViewById (R. id. dialog_animation_txt); Animation animation = AnimationUtils. loadAnimation (context, R. anim. animation_dialog_txt); // The loop playback mode of animation does not work. You can only manually play the animation once after it is played. setAnimationListener (new AnimationListener () {@ Overridepublic void onAnimationEnd (Animation arg0) {Animation anim = AnimationUtils. loadAnimation (context, R. anim. animation_dialog_txt); textView. startAnimation (anim); anim. setAnimationListener (this) ;}@ Overridepublic void onAnimationRepeat (Animation arg0) {// TODO Auto-generated method stub} @ Overridepublic void onAnimationStart (Animation arg0) {// TODO Auto-generated method stub}); // bind the animated textView. startAnimation (animation); return dialog ;}
The Frame Animation file in ImageView is easy to play in sequence for three images. Create res/drawable/animation_dialog.xml
    
     
      
   
  
 
The animation file used by TextView. Create res/anim/animation_dialog_txt.xml
     
      
           
   
  
 


The screenshot effect is too poor, and the actual animation is very smooth. Believe me.

Second, GIF Dynamic Graph implementation
In this way, you can play animated GIF images.
First, this requires a third-party jar package, GifView. jar. Download it and import it to the project.
Create layout file dialog_gif.xml
     
      
   
  
 
Public static Dialog createGIFDialog (final Context context) {final Dialog dialog = new Dialog (context, R. style. dialog); dialog. setContentView (R. layout. dialog_gif); GifView gifView = (GifView) dialog. findViewById (R. id. dialog_gifView); gifView. setGifImage (R. drawable. ride); gifView. showAnimation (); final TextView textView = (TextView) dialog. findViewById (R. id. dialog_gif_txt); Animation animation = AnimationUtils. loadAnimation (context, R. anim. animation_dialog_txt); animation. setAnimationListener (new AnimationListener () {@ Overridepublic void onAnimationEnd (Animation arg0) {Animation anim = AnimationUtils. loadAnimation (context, R. anim. animation_dialog_txt); textView. startAnimation (anim); anim. setAnimationListener (this) ;}@ Overridepublic void onAnimationRepeat (Animation arg0) {// TODO Auto-generated method stub} @ Overridepublic void onAnimationStart (Animation arg0) {// TODO Auto-generated method stub}); // bind the animated textView. startAnimation (animation); return dialog ;}

 







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.