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. <EditText
  8. android:id="@+id/loading_editText_info"
  9. android:layout_width="0dp"
  10. android:layout_height="0dp"/>

Java代码
  1. <preclass="java"name="code">privateImageViewloadingImageView;
  2. privateEditTextloadingEditText;
  3. privateAnimationDrawableanim;</pre>
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. anim=(AnimationDrawable)loadingImageView.getBackground();
  5. loadingEditText.setOnFocusChangeListener(editSetOnFocus);

Java代码
  1. /**
  2. *当输入框获取焦点,则运行动画
  3. */
  4. privateOnFocusChangeListenereditSetOnFocus=newOnFocusChangeListener(){
  5. @Override
  6. publicvoidonFocusChange(Viewv,booleanhasFocus){
  7. //TODOAuto-generatedmethodstub
  8. anim.start();
  9. Log.i("text","执行等待动画。。。。。。。。");
  10. }
  11. };

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

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

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

Java代码
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <animation-listandroid:oneshot="false"xmlns:android="http://schemas.android.com/apk/res/android">
  3. <itemandroid:duration="150"android:drawable="@drawable/load1"/>
  4. <itemandroid:duration="150"android:drawable="@drawable/load2"/>
  5. <itemandroid:duration="150"android:drawable="@drawable/load3"/>
  6. <itemandroid:duration="150"android:drawable="@drawable/load4"/>
  7. <itemandroid:duration="150"android:drawable="@drawable/load5"/>
  8. <itemandroid:duration="150"android:drawable="@drawable/load6"/>
  9. </animation-list>

更多相关文章

  1. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
  2. android为图片生成缩略图
  3. Android(安卓)获取网络状态及调用网络配置界面(转帖)
  4. Android中进行HTTP操作
  5. Android上调用google map api v2
  6. Android(安卓)获取网络时间
  7. Android常用Manager
  8. Android的焦点(Focus)问题
  9. android中ListView控件&&onItemClick事件中获取listView传递的数

随机推荐

  1. PHP生成有背景的二维码图片(代码示例)
  2. 分享学好PHP的几个重要心得
  3. Pimple运行流程浅析(PHP容器)
  4. 在PHP中进行会话处理(代码详解)
  5. 利用php实现读取excel中的图片
  6. PHP中经典的四大排序算法
  7. 一文搞懂PHP类和对象、抽象类、接口
  8. 如何通过imagick让PHP生成PSD文件缩略图(
  9. 实例详解php cookie与session会话基本用
  10. PHP 中的 -> 和 :: 的区别