Android自定义类似ProgressDialog效果的Dialog
Android自定义类似ProgressDialog效果的Dialog.
方法如下:
1.首先准备两张自己要定义成哪样子的效果的图片和背景图片(也可以不要背景)。
如我要的效果:

2.定义loading_dialog.xml布局文件(这里你也可以按自己的布局效果定义,关键是要有个imageView):
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/dialog_view"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:minHeight="60dp"
- android:minWidth="180dp"
- android:gravity="center"
- android:padding="10dp"
- android:background="@drawable/loading_bg">
- <ImageView
- android:id="@+id/img"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/publicloading"
- />
- <TextView
- android:id="@+id/tipTextView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="10dp"
- android:text="数据加载中……" />
- </LinearLayout>
3.定义一个loadingDialog中imageView转动的动画:loading_animation.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android">
- <rotate
- android:interpolator="@android:anim/linear_interpolator"
- android:pivotX="50%"
- android:pivotY="50%"
- android:fromDegrees="0"
- android:toDegrees="+360"
- android:duration="1500"
- android:startOffset="-1"
- android:repeatMode="restart"
- android:repeatCount="-1"/>
- </set>
4.定义dialog的style.
<!-- 自定义loading dialog -->
<style name="loading_dialog" parent="android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@drawable/loading_bg</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
5.写点创建Dialog的代码,你可以自己封装成一个方法。
/**
* 得到自定义的progressDialog
* @param context
* @param msg
* @return
*/
public static Dialog createLoadingDialog(Context context, String msg) { LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.loading_dialog, null);// 得到加载view
LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);// 加载布局
// main.xml中的ImageView
ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);
TextView tipTextView = (TextView) v.findViewById(R.id.tipTextView);// 提示文字
// 加载动画
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
context, R.anim.load_animation);
// 使用ImageView显示动画
spaceshipImage.startAnimation(hyperspaceJumpAnimation);
tipTextView.setText(msg);// 设置加载信息 Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);// 创建自定义样式dialog loadingDialog.setCancelable(false);// 不可以用“返回键”取消
loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));// 设置布局
return loadingDialog; }
最后来张整体的效果图:

-------------------------------------------------------------------------------------------------------------------------------------
上一篇写了使用系统ProgressBar实现的稍微好看的ProgressDialog,如果你想自己的ProgressDialog更具有自己的风格,那用图片去实现,将会达到你的目的。
话不多说,先看效果:
看了上篇以后,实现这个也是很简单的,只需要把布局文件的ProgressBar换成ImageView就可以了。
换成ImageView以后,我们需要让这个ImageView动起来,这就需要对它进行一个anim处理。
实现思路是:用一个动画代替ImageView的图片资源,然后让动画动起来就OK了。
将这个资源当作ImageView的背景图片
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/icon_loading1" android:duration="100"/>
<item android:drawable="@drawable/icon_loading2" android:duration="100"/>
<item android:drawable="@drawable/icon_loading3" android:duration="100"/>
<item android:drawable="@drawable/icon_loading4" android:duration="100"/>
<item android:drawable="@drawable/icon_loading5" android:duration="100"/>
<item android:drawable="@drawable/icon_loading6" android:duration="100"/>
<item android:drawable="@drawable/icon_loading7" android:duration="100"/>
<item android:drawable="@drawable/icon_loading8" android:duration="100"/>
</animation-list>
然后就要在MyProgressDialog类里面让动画启动了
完成这些,然后就可以在Activity里面调用我们的MyProgressDialog了。
为了方便,给大家附上我的图片资源,希望能用得上
Android自定义类似ProgressDialog效果的Dialog的更多相关文章
- Android自定义底部带有动画的Dialog
Android自定义底部带有动画的Dialog 效果图 先看效果图,是不是你想要的呢 自定义Dialog package --.view; import android.app.Dialog; imp ...
- Android 自定义PopupWindow动画效果
public class RollActivity extends Activity { private View view; private Button btn; private PopupWin ...
- 实例源码--Android自定义Gallery动画效果
相关文档与源码: 下载源码 技术要点: 1.自定义控件的使用 2.Gallery控件的使用实例 3.详细的源码注释 ...... 详细介绍: 1.自定义控件的使用 本套源码通过自定义控件的方式,继 ...
- android开发类似coverflow效果的3d旋转
源码下载地址:http://download.csdn.net/detail/feijian_/8888219
- android 自定义progressDialog实现
我们在项目中经常会遇到这样一个应用场景:执行某个耗时操作时,为了安抚用户等待的烦躁心情我们一般会使用进度条之类的空间,在android中让 大家最容易想到的就是progressbar或者progres ...
- (转载)Android自定义ProgressDialog进度等待框
Android自定义ProgressDialog进度等待框 作者:无缘公子 字体:[增加 减小] 类型:转载 时间:2016-01-11我要评论 这篇文章主要介绍了Android自定义Progress ...
- Android 自定义ProgressDialog
Android本身已经提供了ProgressDialog进度等待框,使用该Dialog,我们可以为用户提供更好的体验:在网络请求时,弹出此框等待网络数据. 不过,既然是为了提高用户体验,我们肯定希望该 ...
- Android—自定义Dialog
在 Android 日常的开发中,Dialog 使用是比较广泛的.无论是提示一个提示语,还是确认信息,还是有一定交互的(弹出验证码,输入账号密码登录等等)对话框. 而我们去看一下原生的对话框,虽然随着 ...
- Android 自定义 HorizontalScrollView 打造再多图片(控件)也不怕 OOM 的横向滑动效果
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38140505 自从Gallery被谷歌废弃以后,Google推荐使用ViewPa ...
随机推荐
- 表单提交 多个name相同的input
<form action="{:U('Index/test')}" method="post"> <foreach name="di ...
- Spring中 classpath* 和 classpath 前缀的区别
// org.springframework.core.io.support.ResourcePatternResolver /** * Pseudo URL prefix for all match ...
- e581. Animating an Array of Images in an Application
This is the simplest application to animate an array of images. import java.awt.*; import javax.swin ...
- Java运行时,各种类型存储介绍
Java的内存分配 Java程序运行时的内存结构分成:方法区.栈内存.堆内存.本地方法栈几种. 方法区 存放装载的类数据信息,包括:基本信息:每个类的全限定名.每个类的直接超类的全限定 ...
- (转)MFC的ClistCtrl删除选中多行项目
MFC的ClistCtrl控件添加了多行数据后,若要删除选中的多行数据,可以使用ClistCtrl的成员函数,在网上找了很多例子,发现都有问题,因为在删除ClistCtrl行的时候,删除行下面的行会上 ...
- php -- 取日期
1.获取当前时间方法date()很简单,这就是获取时间的方法, 格式为:date($format, $timestamp), format为格式 - 必需 timestamp为时间戳–可填参数. 比如 ...
- find_circ 识别circRNA 的原理
find_circ 通过识别junction reads 来预测circRNA 和参考基因组比对完之后,首先剔除和基因组完全比对的reads,保留没比对上的reads, 这部分reads 直接比是比对 ...
- Bash 脚本 getopts为什么最后一个參数取不到
看以下的Bash脚本: #!/bin/bash interval=0 count=0 pid="" while getopts "p:d:n" arg do c ...
- ini 文件操作记要(2): 使用 TMemIniFile
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Form ...
- “浪潮杯”山东省第五届ACM大学生程序设计竞赛(总结贴)
第一次參加省赛有点小激动,尽管是作为打星队參赛,但心情却是上下起伏. 5月9号晚上11点多到威海,有点略冷.可是空气比淄博好多了,大家到了旅馆的时候都非常晚了,抱怨了一下三星级的酒店的待遇,喝杯咖啡早 ...