android Tween动画之透明的Dialog(数据加载)
来源:互联网 发布:mac移动硬盘装win10 编辑:程序博客网 时间:2024/05/16 16:49
转载前请注明链接:http://blog.csdn.net/daiwei714/article/details/44059833
相信大家无论是开发什么样的APP都会用到对话框(Dialog),尤其在发送网络请求的时候,为了让用户体验界面的友好性,都会提示一个对话框让客户去等待(其实客户最讨厌这个,转啊转)。
下面为大家提供一个基于Tween动画的透明的用于数据加载的Dialog,先上图:
好了,差不多加载中的时候就是这个样子,下面上代码。
1.CustomProgressBar.java
/** * 自定义进度条 */public class CustomProgressBar extends Dialog{private Context context ;private String progressText ;public CustomProgressBar(Context context) {super(context , R.style.dialog_theme) ;this.context = context ;}public CustomProgressBar(Context context, String progressText) {super(context,R.style.dialog_theme) ;this.context = context ;this.progressText = progressText ;}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.custom_progressbar) ;TextView title = (TextView) findViewById(R.id.custom_imageview_progress_title);title.setText(progressText==null?"加载数据中,请稍后...":progressText) ;}/** * @see android.app.Dialog#show() */@Overridepublic void show() {try{if(!isShowing()){super.show();}}catch (Exception e){e.printStackTrace();}ImageView im = (ImageView) findViewById(R.id.custom_imageview_progress_bar);im.startAnimation(AnimationUtils.loadAnimation(context, R.anim.round_loading));}}
2.Theme的设置 :style.xml (dialog_theme)
<style name="dialog_theme"> <item name="android:windowFrame">@null</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:windowBackground">@color/transparent</item> <!-- 背景透明 --> <!-- 激活背景变暗遮罩 --> <item name="android:backgroundDimEnabled">true</item> <item name="android:backgroundDimAmount">0.6</item> </style>
3.Anim的设置:round_loading.xml
<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromDegrees="0" android:interpolator="@android:anim/linear_interpolator" android:pivotX="50%" android:pivotY="50%" android:repeatCount="infinite" android:toDegrees="+360" />
4.布局文件:custom_progressbar.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/loading_bg" android:padding="15dip" android:gravity="center" android:orientation="vertical" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/custom_imageview_progress_bar" android:src="@drawable/load" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dip" android:id="@+id/custom_imageview_progress_title" android:textColor="@android:color/white" android:textSize="12sp" /></LinearLayout>
下面给大家贴上load的图片:
到这里就可以在activity中调用了:
/* * loading */public void createProgressBar() {this.createProgressBar(null);}public void createProgressBar(String text) {if (progressBar == null) {if (text == null) {progressBar = new CustomProgressBar(this);} else {progressBar = new CustomProgressBar(this, text);}progressBar.setCancelable(true);}if (!progressBar.isShowing()) {progressBar.show();}}public void disMissProgress() {if (progressBar != null && progressBar.isShowing()) {progressBar.dismiss();}}
这里扩展了可以自己设置提示文字,也可以使用默认文字。
谢谢大家的支持,不足之处请多多指出~
0 0
- android Tween动画之透明的Dialog(数据加载)
- android的动画之Tween动画
- Android之Tween动画
- Android游戏开发之Tween动画的实现(三十二)
- Android动画之Tween动画
- android动画之:补间动画(Tween动画)
- Android之动画-Tween动画(线性动画)
- Android之实现带动画加载状态的Dialog
- Android Tween动画之RotateAnimation
- 关于Android动画之Tween
- Android动画之Tween Animation
- android之tween动画详解
- Android动画之Tween Animation
- Android动画之Tween Animation
- Android动画之Tween Animation
- 分析android动画模块之Tween动画(转)
- Android笔记 动画之tween(补间)动画demo
- 史上最简单android动画之Tween Animation(渐变动画)
- CentOS下pip和shadowsocks的安装使用
- 图片音视频应用开发的工具与服务大礼包
- 怎样判断MySQL是否支持分区?
- epoll+反应堆模式
- Android最佳性能实践(二)——分析内存的使用情况
- android Tween动画之透明的Dialog(数据加载)
- 新手vps配置环境之-lnmp配置
- linux系统编程之基础必备(四):C 标准库IO缓冲区和内核缓冲区的区别
- REGISTRY KEY 'SOFTWARE\JAVASOFT\JAVA RUNTIME ENVIRONMENT\CURRENTVERSION'错误 运行java.exe 出现Registry key
- Android 绘制圆形头像
- tabbar红点
- Java中的23种设计模式:
- wegweg
- handler机制的原理