android image加载中等待动画
16lz
2021-12-04
Xml代码
- 在布局中添加一个ImageViw和一个EditText。
- <ImageView
- android:id="@+id/loading_imageView_info"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:background="@anim/loading"/>
- <EditText
- android:id="@+id/loading_editText_info"
- android:layout_width="0dp"
- android:layout_height="0dp"/>
- <preclass="java"name="code">privateImageViewloadingImageView;
- privateEditTextloadingEditText;
- privateAnimationDrawableanim;</pre>
- loadingImageView=(ImageView)findViewById(R.id.loading_imageView_info);
- loadingEditText=(EditText)findViewById(R.id.loading_editText_info);
- loadingEditText.setInputType(InputType.TYPE_NULL);//屏蔽软键盘
- anim=(AnimationDrawable)loadingImageView.getBackground();
- loadingEditText.setOnFocusChangeListener(editSetOnFocus);
- /**
- *当输入框获取焦点,则运行动画
- */
- privateOnFocusChangeListenereditSetOnFocus=newOnFocusChangeListener(){
- @Override
- publicvoidonFocusChange(Viewv,booleanhasFocus){
- //TODOAuto-generatedmethodstub
- anim.start();
- Log.i("text","执行等待动画。。。。。。。。");
- }
- };
当程序获取到数据一般情况是在hanlder中发送消息通知动画停止,并隐藏当前的控件
Java代码- anim.stop();
- loadingImageView.setVisibility(View.GONE);
anim动画在XML中定义,代码如下:
Java代码- <?xmlversion="1.0"encoding="UTF-8"?>
- <animation-listandroid:oneshot="false"xmlns:android="http://schemas.android.com/apk/res/android">
- <itemandroid:duration="150"android:drawable="@drawable/load1"/>
- <itemandroid:duration="150"android:drawable="@drawable/load2"/>
- <itemandroid:duration="150"android:drawable="@drawable/load3"/>
- <itemandroid:duration="150"android:drawable="@drawable/load4"/>
- <itemandroid:duration="150"android:drawable="@drawable/load5"/>
- <itemandroid:duration="150"android:drawable="@drawable/load6"/>
- </animation-list>
更多相关文章
- 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
- android为图片生成缩略图
- Android(安卓)获取网络状态及调用网络配置界面(转帖)
- Android中进行HTTP操作
- Android上调用google map api v2
- Android(安卓)获取网络时间
- Android常用Manager
- Android的焦点(Focus)问题
- android中ListView控件&&onItemClick事件中获取listView传递的数