android image載入中等待動畫,androidimage

來源:互聯網
上載者:User

android image載入中等待動畫,androidimage
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>   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.