zoukankan      html  css  js  c++  java
  • 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>   
  • 相关阅读:
    R vs Python:构建data.frame、读取csv与统计描述
    R语言学习笔记:使用reshape2包实现整合与重构
    Python学习笔记:lambda表达式
    Python学习笔记:startswith & endswith 判断开头结尾是否为指定字符串
    Python学习笔记:一手漂亮的Python函数
    电信行业数据挖掘分析
    Oracle学习笔记:实现select top N的方法
    Oracle学习笔记:ORA-22992 cannot use LOB locators selected from remote tables
    Linux学习笔记:ls和ll命令
    vb常用命名空间
  • 原文地址:https://www.cnblogs.com/xiaochao1234/p/4226879.html
Copyright © 2011-2022 走看看