android image加载中等待动画

Xml代码  收藏代码
  1. 在布局中添加一个ImageViw和一个EditText。  
Xml代码  收藏代码
  1. <ImageView  
  2.       android:id="@+id/loading_imageView_info"  
  3.       android:layout_width="wrap_content"  
  4.       android:layout_height="wrap_content"  
  5.       android:layout_gravity="center"  
  6.       android:background="@anim/loading" />  
  7.   
  8.   <EditText  
  9.       android:id="@+id/loading_editText_info"  
  10.       android:layout_width="0dp"  
  11.       android:layout_height="0dp" />  
Java代码  收藏代码
  1. <pre class="java" name="code">  private ImageView loadingImageView ;  
  2.     private EditText loadingEditText;  
  3.     private AnimationDrawable anim;</pre>  
  4.    
Java代码  收藏代码
  1. loadingImageView =(ImageView)findViewById(R.id.loading_imageView_info);  
  2.     loadingEditText =(EditText)findViewById(R.id.loading_editText_info);  
  3.     loadingEditText.setInputType(InputType.TYPE_NULL);//屏蔽软键盘  
  4.       
  5.     anim = (AnimationDrawable) loadingImageView.getBackground();  
  6.     loadingEditText.setOnFocusChangeListener(editSetOnFocus);  
Java代码  收藏代码
  1. /** 
  2.          * 当输入框获取焦点,则运行动画 
  3.          */  
  4.         private  OnFocusChangeListener editSetOnFocus = new OnFocusChangeListener() {  
  5.               
  6.             @Override  
  7.             public void onFocusChange(View v, boolean hasFocus) {  
  8.                 // TODO Auto-generated method stub  
  9.                 anim.start();  
  10.                 Log.i("text", "执行等待动画。。。。。。。。");  
  11.             }  
  12.         };   

    当程序获取到数据一般情况是在hanlder中发送消息通知动画停止,并隐藏当前的控件

  

Java代码  收藏代码
  1. anim.stop();  
  2. loadingImageView.setVisibility(View.GONE);  

anim动画在XML中定义,代码如下:

Java代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>    
  2. <animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android">    
  3.   
  4.     <item android:duration="150" android:drawable="@drawable/load1" />   
  5.     <item android:duration="150" android:drawable="@drawable/load2" />   
  6.     <item android:duration="150" android:drawable="@drawable/load3" />   
  7.     <item android:duration="150" android:drawable="@drawable/load4" />   
  8.     <item android:duration="150" android:drawable="@drawable/load5" />   
  9.     <item android:duration="150" android:drawable="@drawable/load6" />   
  10.       
  11. </animation-list>   
原文地址:https://www.cnblogs.com/xiaochao1234/p/4226879.html