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>   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM