本文实例为大家分享了Android实现加载对话框的具体代码,供大家参考,具体内容如下

这里简单说一下两种实现加载对话框的方式:1.使用动画让一个图片旋转 2.使用progressbar。

感觉简单来说,dialog就是一个弹出的window,把自己定义的布局放置到window里面就可以了,加载对话框就是有个加载的动画,核心的地方就是实现这个动画,所所以方法  可以有,对图片添加动画,或者使用progressbar。

第一种方式:使用动画让一个图片旋转

先看一下布局:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/dialog_bg_while"

android:orientation="vertical" >

android:layout_width="54dp"

android:id="@+id/loading_dialog_pic"

android:layout_height="54dp"

android:layout_gravity="center_horizontal"

android:layout_marginTop="15dp"

android:background="@drawable/loading" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:layout_marginTop="10dp"

android:text="正在加载..." />

然后自定义Alertdialog,并对图片添加旋转动画:

public class LoadingDialog extends AlertDialog {

private final String DEFAULT_TEXT="正在加载";

private ImageView mImageview;

private TextView mTextView;

private LinearLayout mLayout;

private String mText;

protected LoadingDialog(Context context) {

super(context);

// TODO Auto-generated constructor stub

}

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

mLayout=(LinearLayout) LinearLayout.inflate(getContext(), R.layout.loading_dialog, null);

mImageview=(ImageView) mLayout.findViewById(R.id.loading_dialog_pic);

mTextView=(TextView) mLayout.findViewById(R.id.loading_dialog_text);

loadanimation();

getWindow().setContentView(mLayout);

}

private void loadanimation() {//对图片添加旋转动画

// TODO Auto-generated method stub

Animation anim=AnimationUtils.loadAnimation(getContext(), R.anim.loading_dialog_anim);

LinearInterpolator lin = new LinearInterpolator();

anim.setInterpolator(lin);

mImageview.setAnimation(anim);

}

}

看一下xml的动画:

android:duration="1500"

android:pivotX="50%"

android:pivotY="50%"

android:fromDegrees="0.0"

android:repeatCount="infinite"

android:toDegrees="-358" />

第二种方式:使用progressbar

首先是一个animation-list:

android:drawable="@drawable/loading1"

android:duration="100"/>

android:drawable="@drawable/loading2"

android:duration="100"/>

android:drawable="@drawable/loading3"

android:duration="100"/>

android:drawable="@drawable/loading4"

android:duration="100"/>

android:drawable="@drawable/loading5"

android:duration="100"/>

android:drawable="@drawable/loading6"

android:duration="100"/>

android:drawable="@drawable/loading7"

android:duration="100"/>

android:drawable="@drawable/loading8"

android:duration="100"/>

看一下布局的实现:

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/dialog_bg_while"

android:orientation="vertical" >

style="@android:style/Widget.ProgressBar.Large"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:layout_marginTop="10dp"

android:indeterminateDrawable="@drawable/loading_animation_list"

android:indeterminateDuration="1500" />

android:layout_width="match_parent"

android:layout_height="1dp"

android:background="#00BCD4" />

android:id="@+id/loading_dialog_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:layout_marginTop="10dp"

android:text="正在加载..." />

然后自定义一个alertdialog:

public class LoadingDialog extends AlertDialog {

private final String DEFAULT_TEXT="正在加载";

private TextView mTextView;

private LinearLayout mLayout;

private String mText;

protected LoadingDialog(Context context) {

super(context);

// TODO Auto-generated constructor stub

}

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

mLayout=(LinearLayout) LinearLayout.inflate(getContext(), R.layout.loading_dialog, null);

mTextView=(TextView) mLayout.findViewById(R.id.loading_dialog_text);

WindowManager m=(WindowManager) getContext().getSystemService(getContext().WINDOW_SERVICE);

int windowwith=m.getDefaultDisplay().getWidth();

int w=windowwith*3/5;

int h=300;

getWindow().setLayout(w, h);//设置对话框窗体大小

getWindow().setContentView(mLayout);

}

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持得牛网。

加载对话框Android,Android实现加载对话框相关推荐

  1. Android仿美团加载数据、小人奔跑进度动画对话框(附顺丰快递员奔跑效果)

    我们都知道在Android中,常见的动画模式有两种:一种是帧动画(Frame Animation),一种是补间动画(Tween Animation).帧动画是提供了一种逐帧播放图片的动画方式,播放事先 ...

  2. 安卓学习笔记---Android仿美团加载数据、小人奔跑进度动画对话框(以及顺丰快递员奔跑效果)

    最近要加一个动态的加载功能,类似于美团的效果,这篇文章写的很好,可以借鉴 博客地址: http://blog.csdn.net/jdsjlzx/article/details/43489395 我们都 ...

  3. android 加载条封装,Android基于JsBridge封装的高效带加载进度的WebView

    图片发自简书App 概述 从去年4月项目就一直用起了JsBridge,前面也针对jsBridge使用姿势介绍过一篇入门篇,<Android JsBridge实战 打造专属你的Hybrid APP ...

  4. Android studio3.6 加载系统内置矢量图标icon的操作步骤

    用Android studio开发过程中,不可避免要用到很多图标,其中最常用的是xml格式的矢量图标,那么这些图标是怎么做出来的呢,两种方法:第一,使用AS系统内部嵌入的图标:第二,使用网上第三方所做 ...

  5. Android 高清加载巨图方案 拒绝压缩图片

    Android 高清加载巨图方案 拒绝压缩图片 转载请标明出处:  http://blog.csdn.net/lmj623565791/article/details/49300989:  本文出自: ...

  6. Android类动态加载技术

    Android类动态加载技术 Android应用开发在一般情况下,常规的开发方式和代码架构就能满足我们的普通需求.但是有些特殊问题,常常引发我们进一步的沉思.我们从沉思中产生顿悟,从而产生新的技术形式 ...

  7. Android studio 使用心得(六)---android studio 如何加载.so文件

    2019独角兽企业重金招聘Python工程师标准>>> 之前一直没怎么注意,以为.so文件android为像eclipse一样直接加载,但是直到昨天我在android studio上 ...

  8. android 加载进度,Android实现图片加载进度提示

    本文实例为大家分享了Android实现图片加载进度提示的具体代码,供大家参考,具体内容如下 先上图: 实现原理: 第一个控件的实现原理是重写ImageView的onDraw()方法,利用Canvas的 ...

  9. 【Android 逆向】加壳技术简介 ( 动态加载 | 第一代加壳技术 - DEX 整体加固 | 第二代加壳技术 - 函数抽取 | 第三代加壳技术 - VMP / Dex2C | 动态库加壳技术 )

    文章目录 一.动态加载 二.第一代加壳技术 ( DEX 整体加固 ) 三.第二代加壳技术 ( 函数抽取 ) 四.第三代加壳技术 ( Java 函数 -> Native 函数 ) 五.so 动态库 ...

  10. Android ListView异步加载图片乱序问题,原因分析及解决方案

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/45586553 在Android所有系统自带的控件当中,ListView这个控件算是 ...

最新文章

  1. 【CSON原创】HTML5游戏框架cnGameJS开发实录(外部输入模块篇)
  2. Django 中的 cookie 和 session
  3. 《Windows Forms编程》,真正的好书!
  4. 《第3选择》学习笔记
  5. go语言mysql操作_使用Go语言操作MySQL数据库的思路与步骤
  6. 【Hankson 的趣味题】
  7. layui上传文件请求接口异常_SpringMVC实现文件上传与下载,拦截器,异常处理
  8. Windows phone 应用开发[14]-调用WebBrowser
  9. bat文件运行java的jar包不弹出dos窗口,开机自启jar包
  10. 使用Python处理声音文件(五):绘制立体声音乐左右声道频谱
  11. Java各种日期计算
  12. spring整合cxf,轻松编写webService客户端、服务端
  13. 评委输入的密码如果不正确,当错误的次数达到5次时,该评委的账号会被锁定.如何解锁呢?
  14. elementui中下拉菜单需要传入多个参数的处理
  15. 最最简单的使用DW编程软件
  16. 如何提高有效工作效率
  17. 华为这次是给所有企业挡了子弹
  18. xml与txt文件格式互换
  19. 如何进行测试用例评审
  20. 汽车UDS诊断详解及Vector相关工具链使用说明——2.3.2 故障码状态(statusOfDTC)详解

热门文章

  1. LeetCode——75. 颜色分类(面试题)
  2. 将通达信的背景设置成白色
  3. 蚁群算法原理及python实现
  4. Java--数组和集合区别
  5. Matab六自由度机械臂建模的偷懒方法
  6. 数据分析思维:分析方法和业务知识
  7. 怎样才能从Java初级程序员成长为一名合格的架构师?
  8. oppoa5降级教程_OPPO A5官方原版固件rom系统刷机包升级包下载A.12版
  9. 电脑编程软件都有哪些
  10. 圣思园的随堂视频发布了