先看看实现效果图

1.首先自定义一个类继承系统ProgressDialog

/**
* Created by hanbao0928 on 2018/11/1.
*/ public class DialogUtils extends ProgressDialog {
public DialogUtils(Context context) {
super(context);
} public DialogUtils(Context context, int theme) {
super(context, theme);
} @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); init(getContext());
} private void init(Context context) {
setCancelable(true);
setCanceledOnTouchOutside(false); setContentView(R.layout.loading);//loading的xml文件
WindowManager.LayoutParams params = getWindow().getAttributes();
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
getWindow().setAttributes(params);
} @Override
public void show() {//开启
super.show();
} @Override
public void dismiss() {//关闭
super.dismiss();
}
}

2.设置loading布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/shape_dialog_bg"//背景色
android:layout_centerInParent="true"
android:orientation="vertical"> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"> <ProgressBar
android:id="@+id/pb_load"
android:layout_width="65dp"
android:layout_height="65dp"
android:indeterminateDrawable="@drawable/progressbar"//加载圈的样式
android:layout_centerInParent="true"/> </RelativeLayout> <TextView
android:id="@+id/tv_load_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="加载中..."
android:textColor="#9a9b98"
android:textSize="12sp"/> </LinearLayout>

3.背景色(可自行调整)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <corners android:radius="8dp" />
<solid android:color="#88000000" />
</shape>

4.加载圈样式(可自行调整)

<animated-rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%" android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="720"> <shape
android:shape="ring"
android:innerRadiusRatio="3"
android:thicknessRatio="15"
android:useLevel="false">
<gradient
android:type="sweep"
android:useLevel="false"
android:startColor="#55c6c6c6"
android:centerColor="#c6c6c6"
android:centerY="0.50"
android:endColor="#c6c6c6" />
</shape> </animated-rotate>

5.原来需要在创建自定义的loading 的时候在传入 new Loading_view(this,R.style.CustomDialog);样式

<style name="CustomDialog" parent="Theme.AppCompat.Dialog">
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>

6.代码中使用

public class MainActivity extends AppCompatActivity {

    private DialogUtils loading;

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); } public void loding(View v){//点击加载并按钮模仿网络请求 loading = new DialogUtils(this,R.style.CustomDialog);
loading.show();
new Handler().postDelayed(new Runnable() {//定义延时任务模仿网络请求
@Override
public void run() {
loading.dismiss();//3秒后调用关闭加载的方法
}
}, 1000);
}
}

ok  这样就实现菊花加载效果啦!!!!

Android 菊花加载工具类的更多相关文章

  1. 161216、使用spring的DefaultResourceLoader自定义properties文件加载工具类

    import java.io.IOException; import java.io.InputStream; import java.util.NoSuchElementException; imp ...

  2. 使用spring的DefaultResourceLoader自定义properties文件加载工具类

    转自:https://www.cnblogs.com/zrbfree/p/6230957.html import java.io.IOException; import java.io.InputSt ...

  3. android实现异步加载图片类

    其中牵涉到的关键知识点 1,回调机制,不过回调接口的实现方式有多种多样,可以是一个类继承该接口,也可以是作为一个方法参数: 可以参照自己的这篇博客: http://www.cnblogs.com/bo ...

  4. Android图片加载框架最全解析(八),带你全面了解Glide 4的用法

    本篇将是我们这个Glide系列的最后一篇文章. 其实在写这个系列第一篇文章的时候,Glide就推出4.0.0的RC版了.那个时候因为我一直研究的都是Glide 3.7.0版本,再加上RC版本还不太稳定 ...

  5. Android应用开发提高系列(4)——Android动态加载(上)——加载未安装APK中的类

    前言 近期做换肤功能,由于换肤程度较高,受限于平台本身,实现起来较复杂,暂时搁置了该功能,但也积累了一些经验,将分两篇文章来写这部分的内容,欢迎交流! 关键字:Android动态加载 声明 欢迎转载, ...

  6. 在Android的App中动态的加载Java类

    原文的地址:http://yenliangl.blogspot.com/2009/11/dynamic-loading-of-classes-in-your.html 我正在编写一个应用程序能够加载别 ...

  7. [转载] Android动态加载Dex机制解析

    本文转载自: http://blog.csdn.net/wy353208214/article/details/50859422 1.什么是类加载器? 类加载器(class loader)是 Java ...

  8. Android图片加载库的理解

    前言     这是“基础自测”系列的第三篇文章,以Android开发需要熟悉的20个技术点为切入点,本篇重点讲讲Android中的ImageLoader这个库的一些理解,在Android上最让人头疼是 ...

  9. Android 动态加载 (一) 态加载机制 案例一

    在目前的软硬件环境下,Native App与Web App在用户体验上有着明显的优势,但在实际项目中有些会因为业务的频繁变更而频繁的升级客户端,造成较差的用户体验,而这也恰恰是Web App的优势.本 ...

随机推荐

  1. Java核心-多线程-并发控制器-Semaphore信号量

    Semaphore是非常有用的一个多线程并发控制组件(Java还有CountDownLatch.CyclicBarrier.Exchanger多线程组件),它相当于是一个并发控制器,是用于管理信号量的 ...

  2. WebApi设置HttpContext.Current.User

    1.Web.config配置上system.web节点下加入以下配置 <system.web> <authentication mode="Forms"> ...

  3. Nginx设置防止IP及非配置域名访问

    #设置IP或其它域名访问时返回500或304 server{ listen default; server_name _; ##标示空主机头 return ; } #设置IP或其它域名访问时重定向到w ...

  4. JAVA除法保留小数点后两位的两种方法

      1.(double) (Math.round(sd3*10000)/10000.0);  这样为保持4位 (double) (Math.round(sd3*100)/100.0); 这样为保持2位 ...

  5. C语言,链表操作

    #include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <string ...

  6. 快速傅里叶变换(FFT)时间复杂度

    图:信号在时域上和频域上的直观表示 1. 计算一维离散傅里叶变换(DFT)公式如下: 其中,N表示数据长度.由上式可知,DFT的时间复杂度是O(N*N) 2. 一维FFT的时间复杂度为O(N*logN ...

  7. mysql中的int和tinyint、varchar和char、DateTime和TimeStamp区别

    一.int和tinyint的区别 大小: tinyint在mysql中占用1个字节 即: 1 bytes = 8 bit ,一个字节最多可以代表的数据长度是2的8次方:11111111 = 256 在 ...

  8. 装python package 时,conda提示会升级python2到python3,那可能是你的windows不支持py2env下的此包。

    装python package 时,conda提示会升级python2到python3, 那可能是你的windows不支持py2env下的此包.比如:win 下,tensorflow就不支持py2的环 ...

  9. Delphi 字母 递增 递减算法

    网上看了一下,好象没有现成的,自己随手写了一下,给大家参考一下吧 // a..z 97..122 A..Z 65..90 function UpABC(ABC : String; AddCount : ...

  10. PHP超全局变量$_SERVER分析

    $_SERVER 是一个包含了诸如头信息(header).路径(path).以及脚本位置(script locations)等等信息的数组.这个数组中的项目由 Web 服务器创建.不能保证每个服务器都 ...