package com.loaderman.loadingdialogdemo;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.TextView; /**
* LoadingDialog.java
*/ public class LoadingDialog extends Dialog {
private static final int CHANGE_TITLE_WHAT = 1;
private static final int CHNAGE_TITLE_DELAYMILLIS = 300;
private static final int MAX_SUFFIX_NUMBER = 3;
private static final char SUFFIX = '.'; private ImageView iv_route;
private TextView tv;
private TextView tv_point;
private RotateAnimation mAnim;
private boolean cancelable = true; private Handler handler = new Handler() {
private int num = 0; public void handleMessage(android.os.Message msg) {
if (msg.what == CHANGE_TITLE_WHAT) {
StringBuilder builder = new StringBuilder();
if (num >= MAX_SUFFIX_NUMBER) {
num = 0;
}
num++;
for (int i = 0; i < num; i++) {
builder.append(SUFFIX);
}
tv_point.setText(builder.toString());
if (isShowing()) {
handler.sendEmptyMessageDelayed(CHANGE_TITLE_WHAT, CHNAGE_TITLE_DELAYMILLIS);
} else {
num = 0;
}
}
} ;
}; public LoadingDialog(Context context) {
super(context, R.style.Dialog_bocop);
init();
} private void init() {
View contentView = View.inflate(getContext(), R.layout.activity_custom_loding_dialog_layout, null);
setContentView(contentView); contentView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (cancelable) {
dismiss();
}
}
});
iv_route = (ImageView) findViewById(R.id.iv_route);
tv = (TextView) findViewById(R.id.tv);
tv_point = (TextView) findViewById(R.id.tv_point);
initAnim();
//getWindow().setWindowAnimations(R.anim.alpha_in);
} private void initAnim() {
mAnim = new RotateAnimation(360, 0, Animation.RESTART, 0.5f, Animation.RESTART, 0.5f);
mAnim.setDuration(2000);
mAnim.setRepeatCount(Animation.INFINITE);
mAnim.setRepeatMode(Animation.RESTART);
mAnim.setStartTime(Animation.START_ON_FIRST_FRAME);
} @Override
public void show() {
iv_route.startAnimation(mAnim);
handler.sendEmptyMessage(CHANGE_TITLE_WHAT);
super.show();
} @Override
public void dismiss() {
mAnim.cancel();
super.dismiss();
} @Override
public void setCancelable(boolean flag) {
cancelable = flag;
super.setCancelable(flag);
} @Override
public void setTitle(CharSequence title) {
tv.setText(title);
} @Override
public void setTitle(int titleId) {
setTitle(getContext().getString(titleId));
}
}
package com.loaderman.loadingdialogdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View; public class MainActivity extends AppCompatActivity {
LoadingDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_loding_dialog_main);
dialog = new LoadingDialog(this);
}
public void btnClick(View v) {
dialog.show();
}
}

在res/anim文件下新建alpha_in.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromAlpha="0.0"
android:toAlpha="1.0"
>
</alpha>

在res/layout文件下新建activity_custom_loding_dialog_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:orientation="vertical"> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/bt_pay_selector"
android:onClick="btnClick"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:text="show Dialog"
android:textColor="@android:color/white"/> </RelativeLayout>

在res/layout文件下新建activity_custom_loding_dialog_layout.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:gravity="center"> <LinearLayout
android:layout_width="220dp"
android:layout_height="220dp"
android:layout_gravity="center"
android:background="@drawable/dialog_bocop_loaing_bg"
android:orientation="vertical"> <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center"> <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="3dp"
android:src="@mipmap/ic_launcher"/> <ImageView
android:id="@+id/iv_route"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/dialog_bocop_loading_rotate_anim_img"/>
</RelativeLayout> <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:gravity="center_horizontal"> <TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/tv_point"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:text="正在加载"
android:textColor="#6F6868"
android:textSize="20sp"
/> <TextView
android:id="@+id/tv_point"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="..."
android:textColor="#6F6868"
android:textSize="20sp"/>
</RelativeLayout>
</LinearLayout> </LinearLayout>

效果图:

LoaderDialog自定义加载框的实现的更多相关文章

  1. ios新手开发——toast提示和旋转图片加载框

    不知不觉自学ios已经四个月了,从OC语法到app开发,过程虽然枯燥无味,但是结果还是挺有成就感的,在此分享我的ios开发之路中的小小心得~废话不多说,先上我们今天要实现的效果图: 有过一点做APP经 ...

  2. 使用Dialog实现全局Loading加载框

    Dialog实现全局Loading加载框 很多人在实现Loading加载框的时候,都是在当前的页面隐藏一个Loading布局,需要加载的时候,显示出来,加载完再隐藏 使用Dialog实现Loading ...

  3. mui---取消掉默认加载框

    我们在进行打开页面新页面的时候,在APP中会在中间有一个加载框,考虑到用户体验,要取消掉,具体方法是,对openWindow进行配置: 具体参考:http://dev.dcloud.net.cn/mu ...

  4. Android--自定义加载框

    1,在网上看了下好看的加载框,看了一下,挺好看的,再看了下源码,就是纯paint画出来的,再加上属性动画就搞定了 再来看一下我们的源码 LvGhost.java package com.qianmo. ...

  5. Android 自定义View修炼-自定义加载进度动画XCLoadingImageView

    一.概述 本自定义View,是加载进度动画的自定义View,继承于ImageView来实现,主要实现蒙层加载进度的加载进度效果. 支持水平左右加载和垂直上下加载四个方向,同时也支持自定义蒙层进度颜色. ...

  6. 一个mui扩展插件mui.showLoading加载框【转】

    转:http://ask.dcloud.net.cn/article/12856 写在前面:好像mui目前dialog系列唯独缺少showLoading加载框(加载中)组件,为了统一组件样式和体验,写 ...

  7. Android:webView加载h5网页视频,播放不了,以及横屏全屏的问题和实现自定义加载进度条的效果

    1.webView加载h5网页视频,播放不了,android3.0之后要在menifest添加硬件加速的属性 android:hardwareAccelerated="true". ...

  8. Java类加载机制及自定义加载器

    转载:https://www.cnblogs.com/gdpuzxs/p/7044963.html Java类加载机制及自定义加载器 一:ClassLoader类加载器,主要的作用是将class文件加 ...

  9. asp.net读取用户控件,自定义加载用户控件

    1.自定义加载用户控件 ceshi.aspx页面 <html> <body> <div id="divControls" runat="se ...

随机推荐

  1. 语义分割之RefineNet

    背景介绍 近来年,深度卷积网络在目标检测方面取得了一定的成绩.但对于密集预测,仍存在一定不足,原因是频繁的卷积和池化导致最终的特征分辨率降低. 针对这个问题,目前主要采用两种方法:第一种:空洞卷积,如 ...

  2. Oracle【多表查询操作(SQL92&SQL99)】

    多表联合查询:需要获取的数据分布在多张表中 SQL92: --笛卡尔积:将多个表的数据进行一一对应,所得的结果为多表的笛卡尔积 select * from emp; select * from dep ...

  3. 【原创】马哥 文本三剑客之awk

    命令 awk 全称: man搜索: 简述 基本用法 选项 用法与实验 print 打印 (1)(2)(3) 变量 1.内建变量 FS与OFS RS与ORS NR与FNR NF ARGC与ARGC 2. ...

  4. IDEA利用mybatis-generator自动生成dao和mapper

    pom.xml配置 <properties> <java.version>1.8</java.version> <mybatis-generator-core ...

  5. Linux系统组成和获取命令帮助4

    Linux文件系统:        1.文件名名称严格区分字符大小写        2.文件可以使用除/以外任意字符        3.文件名长度不能超过255字符        4.以.开头的文件为 ...

  6. 【2017中国大学生程序设计竞赛-哈尔滨站】B - K-th Number

    原题: 题意: 给你一个长度为N的正整数组A,对于这个数组的所有子区间,若长度小于k则不管它,若长度大于等于k则取第k大放入数组B 问你B中第M大的数是谁 一眼序列分治,然而没思路 数据结构?能想到从 ...

  7. 重温JSP学习笔记

    <% double d1 = 3.5; double d2 = 4.4; pageContext.setAttribute("d1", d1); pageContext.se ...

  8. 14-SQLServer索引碎片

    一.总结 1.数据库的存储本身是无序的,建立聚集索引之后,就会按照聚集索引的物理顺序存入硬盘: 2.建立索引完全是为了提升读取的速度,相对写入的速度就会降低,没有索引的表写入时最快的,但是大多数系统读 ...

  9. 给PS添加ICO格式文件

    为什么你的ps不能直接打开favicon.ico文件呢?因为你没有安装识别ico的格式插件. 安装步骤如下: 下载格式文件:https://pan.baidu.com/s/1lE0El1VtDqD5l ...

  10. luogu 3857 [TJOI2008]彩灯 线性基

    可以将每一个开关控制的灯的序列看作是0/1组成的二进制. 由于灯的开和关是满足异或的性质的,所以直接求一下线性基大小即可. 答案为 $2^{size}.$ #include <cstdio> ...