Android自定义类似ProgressDialog效果的Dialog.

方法如下:

1.首先准备两张自己要定义成哪样子的效果的图片和背景图片(也可以不要背景)。

如我要的效果:

2.定义loading_dialog.xml布局文件(这里你也可以按自己的布局效果定义,关键是要有个imageView):

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/dialog_view"
  4. android:orientation="vertical"
  5. android:layout_width="fill_parent"
  6. android:layout_height="fill_parent"
  7. android:minHeight="60dp"
  8. android:minWidth="180dp"
  9. android:gravity="center"
  10. android:padding="10dp"
  11. android:background="@drawable/loading_bg">
  12. <ImageView
  13. android:id="@+id/img"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:src="@drawable/publicloading"
  17. />
  18. <TextView
  19. android:id="@+id/tipTextView"
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:layout_marginLeft="10dp"
  23. android:text="数据加载中……" />
  24. </LinearLayout>

3.定义一个loadingDialog中imageView转动的动画:loading_animation.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android">
  3. <rotate
  4. android:interpolator="@android:anim/linear_interpolator"
  5. android:pivotX="50%"
  6. android:pivotY="50%"
  7. android:fromDegrees="0"
  8. android:toDegrees="+360"
  9. android:duration="1500"
  10. android:startOffset="-1"
  11. android:repeatMode="restart"
  12. android:repeatCount="-1"/>
  13. </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的更多相关文章

  1. Android自定义底部带有动画的Dialog

    Android自定义底部带有动画的Dialog 效果图 先看效果图,是不是你想要的呢 自定义Dialog package --.view; import android.app.Dialog; imp ...

  2. Android 自定义PopupWindow动画效果

    public class RollActivity extends Activity { private View view; private Button btn; private PopupWin ...

  3. 实例源码--Android自定义Gallery动画效果

    相关文档与源码: 下载源码   技术要点: 1.自定义控件的使用 2.Gallery控件的使用实例 3.详细的源码注释 ...... 详细介绍: 1.自定义控件的使用 本套源码通过自定义控件的方式,继 ...

  4. android开发类似coverflow效果的3d旋转

    源码下载地址:http://download.csdn.net/detail/feijian_/8888219

  5. android 自定义progressDialog实现

    我们在项目中经常会遇到这样一个应用场景:执行某个耗时操作时,为了安抚用户等待的烦躁心情我们一般会使用进度条之类的空间,在android中让 大家最容易想到的就是progressbar或者progres ...

  6. (转载)Android自定义ProgressDialog进度等待框

    Android自定义ProgressDialog进度等待框 作者:无缘公子 字体:[增加 减小] 类型:转载 时间:2016-01-11我要评论 这篇文章主要介绍了Android自定义Progress ...

  7. Android 自定义ProgressDialog

    Android本身已经提供了ProgressDialog进度等待框,使用该Dialog,我们可以为用户提供更好的体验:在网络请求时,弹出此框等待网络数据. 不过,既然是为了提高用户体验,我们肯定希望该 ...

  8. Android—自定义Dialog

    在 Android 日常的开发中,Dialog 使用是比较广泛的.无论是提示一个提示语,还是确认信息,还是有一定交互的(弹出验证码,输入账号密码登录等等)对话框. 而我们去看一下原生的对话框,虽然随着 ...

  9. Android 自定义 HorizontalScrollView 打造再多图片(控件)也不怕 OOM 的横向滑动效果

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38140505 自从Gallery被谷歌废弃以后,Google推荐使用ViewPa ...

随机推荐

  1. debian配置网络

    http://blog.csdn.net/ypist/article/details/8513274 vim /etc/resolv.conf   配置域名服务器 search test.ivic.o ...

  2. 【转】ImageView的Scaletype参数设置

    ImageView的Scaletype决定了图片在View上显示时的样子,如进行何种比例的缩放,及显示图片的整体还是部分,等等. 设置的方式包括: 1. 在layout xml中定义Android:s ...

  3. sendEvent()

    sendEvent()(QObject *receiver, QEvent *event)可以将自己创建事件event发送给制定的receiver 例如, //创建按键事件 QKeyEvent key ...

  4. 在对listctrl的控件进行重载的过程中,GetHeaderCtrl()返回NULL的问题

    先谈谈我的问题吧! 在使用listctrl的过程中,我需要在列表头部添加checkbox,实现全选的功能. 经过网上资料的罗列,我找到了一个demo,使用的重绘的方法,在使用的过程中,我发现我的列表头 ...

  5. perl 利用管道读取压缩文件内容

    perl的文件句柄不仅支持普通文件, 还支持管道,今天需要统计一个fastq文件中的序列数和碱基数,而NGS的fastq文件一般都是gzip压缩的,所以 需要读取压缩文件中的内容,代码如下: my ( ...

  6. maven 打包可执行jar的两种方法

    1.修改pom.xml增加如下内容 <build> <pluginManagement> <plugins> <plugin> <groupId& ...

  7. Kubernetes(二)架构及资源关系简单总结

    Kubernetes架构 先引用一下官方的架构图: 对于本文来说,我觉得这张图有点复杂了,但是我又懒得自己画了,就用这张吧.Kubernetes是一个集群,和传统的集群相似,它也是有一个主节点和若干个 ...

  8. c语言的fopen

    c语言fopen函数 fopen函数用来打开一个文件,其调用的一般形式为: 文件指针名=fopen(文件名,使用文件方式); 其中, “文件指针名”必须是被说明为FILE 类型的指针变量: “文件名” ...

  9. Java基础--生成验证码

    HTML <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnco ...

  10. Getting SharePoint objects (spweb, splist, splistitem) from url string

    You basically get anything in the object model with one full url: //here is the site for the url usi ...