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 ...
随机推荐
- svg 添加超链接
<svg> <a xlink:href="http://www.w3.org//Graphics//SVG//Overview.htm8"> ...
- 修改jvm内存大小
- 【MySQL】字符串截取之substring_index
substring_index(str,delim,count) str:要处理的字符串 delim:分隔符 count:计数 例子:str=www.baidu.c ...
- 【转】MFC 各类型相互转换
MFC下的常用字符串数据类型表示的含义: L:Long 长 P:Point 指针 C:Const 常量 W:Wchar_t 宽字符 T:TCHAR STR:String 字符串 在看看MF ...
- rar安装和使用
参考:http://blog.csdn.net/dracotianlong/article/details/18011033 .下载rar wget http://www.rarlab.com/rar ...
- Understanding the difficulty of training deep feedforward neural networks
本文作者为:Xavier Glorot与Yoshua Bengio. 本文干了点什么呢? 第一步:探索了不同的激活函数对网络的影响(包括:sigmoid函数,双曲正切函数和softsign y = x ...
- e656. 创建基本图形
Shape line = new Line2D.Float(x1, y1, x2, y2); Shape arc = new Arc2D.Float(x, y, w, h, start, extent ...
- 转载:mysql 操作总结 INSERT和REPLACE
转自:http://www.jb51.net/article/19411.htm 用于操作数据库的SQL一般分为两种,一种是查询语句,也就是我们所说的SELECT语句,另外一种就是更新语句,也叫做 ...
- par函数的ann 参数-控制图片的注释信息
ann 参数控制图片的x轴和y轴标签以及标题是否显示 默认值为TRUE, 所以图片有对应的信息时,会显示出来,代码示例 plot(1:5, 1:5, main = "title", ...
- 利用PHPExcel导出Excel相关设置
功能包括: 1.设置单元格格式,包括单元格边框.单元格高度.单元格宽度 2.合并指定的单元格 3.设置Excel数据源,并将数据源保护起来(这个是为了实现单元格下拉选项功能) 4.设置字体样式 pub ...