它们的定义AlertDialog(二)
先来看主页面布局
main_activity.xml里面仅仅有一个button(加入点击事件。弹出载入框)
再看MainActivity
package com.example.loadingdialog; import android.app.Activity;
import android.os.Bundle;
import android.view.View; public class MainActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.main_activity);
findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
LoadingDialog loadingDialog = new LoadingDialog(MainActivity.this);
loadingDialog.setCancelable(false);
loadingDialog.show();
}
});
}
}
看载入框的布局文件
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: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>
LoadingDialog(里面有具体的凝视)
package com.example.loadingdialog; 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; 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;
/**
* 定义一个handler,载入就发送一个即时消息,让原点+1,继而在每隔300毫秒发送一个延迟消息,来添加+1
*/
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);
} }
再看super(context, R.style.Dialog_bocop);
背景色,无标题属性
<style name="Dialog_bocop">
<item name="android:windowBackground">@color/bocop_dialog_bg</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
</style>
在color.xml文件里
<? xml version="1.0" encoding="utf-8"? >
<resources>
<color name="bocop_dialog_bg">#77000000</color>
</resources>
<!-- window背景色 -->
接下来看这个getWindow().setWindowAnimations(R.anim.alpha_in);
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="1.0"
android:toAlpha="0.0" > </alpha>
它们的定义AlertDialog(二)的更多相关文章
- {MySQL的逻辑查询语句的执行顺序}一 SELECT语句关键字的定义顺序 二 SELECT语句关键字的执行顺序 三 准备表和数据 四 准备SQL逻辑查询测试语句 五 执行顺序分析
MySQL的逻辑查询语句的执行顺序 阅读目录 一 SELECT语句关键字的定义顺序 二 SELECT语句关键字的执行顺序 三 准备表和数据 四 准备SQL逻辑查询测试语句 五 执行顺序分析 一 SEL ...
- java怎么定义一个二维数组?
java中使用 [][] 来定义二维数组 定义数组时也可同时初始化下面是一些例子float[][] numthree; //定义一个float类型的2维数组numthree=new float[5][ ...
- C语言数组:C语言数组定义、二维数组、动态数组、字符串数组
1.C语言数组的概念 在<更加优美的C语言输出>一节中我们举了一个例子,是输出一个 4×4 的整数矩阵,代码如下: #include <stdio.h> #include &l ...
- 自己定义AlertDialog对话框布局
自己定义对话框中的信息body布局 LayoutInflater inflater =getLayoutInflater(); View layout = inflater.inflate(R.lay ...
- vector 定义的二维数组的遍历
之前我们分享了STL的一些容器,再介绍vector中只介绍了二维的vector的定义并没有说二维的vector怎么遍历,那么我们今天就来看下二维的vector怎么遍历 看下面的代码吧. #includ ...
- 教你看懂C++类库函数定义之二---STDMETHOD介绍
一切从一个C++ 类库头文件开始,现在在做一个C++的项目,期间用到一个开源的界面库DUILib(类似MFC),这个东西还不错能很容易的写出漂亮的界面,比如QQ的界面,可以去下载下来研究研究,地址:h ...
- Android 自己定义View (二) 进阶
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24300125 继续自己定义View之旅.前面已经介绍过一个自己定义View的基础 ...
- Python学习-10.Python函数定义(二)
在Python中定义函数的时候,可以使用参数默认值的方式定义函数 例子: def welcome(who,state='is',action='talking'): print(who,state,a ...
- bbs-admin-自定义admin(二)
本文内容 目的:模仿admin默认配置,自定义配置类 一 查 1 查看数据 2 查看表头 3 分页器 4 search(搜索框) 5 action(批量处理) 6 filter(分类) ...
随机推荐
- WebBrowser脚本错误的完美解决方案
原文:WebBrowser脚本错误的完美解决方案 当IE浏览器遇到脚本错误时浏览器,左下角会出现一个黄色图标,点击可以查看脚本错误的详细信息,并不会有弹出的错误信息框.当我们使用WebBrowse ...
- adb 之android的神器am
am命令,am全称activity manager,你能使用am去模拟各种系统的行为,例如去启动一个activity,强制停止进程,发送广播进程,修改设备屏幕属性等等 命令窗口通过adb shell ...
- [Java 8] (6) Lambda与资源管理
资源处理 Java本身自带了垃圾回收(Garbage Collection)功能.可是仅仅有垃圾回收的目标是内部资源(Internal Resource),典型的比方堆上分配的内存区域等.对于外部资源 ...
- GNU GPL介绍
怎样在程序中使用GNU许可证 不管使用哪种许可证,使用时须要在每一个程序的源文件里加入两个元素:一个版权声明和一个复制许可声明.说明该程序使用GNU许可证进行授权.另外在声明版权前应该说明 ...
- JavaFX游戏开发效率浅谈
声明: 本博客文章原创类别的均为个人原创,版权所有.转载请注明出处: http://blog.csdn.net/ml3947,另外本人的个人博客:http://www.wjfxgame.com. ...
- hdu 4963(中途相遇法)
题目链接:Dividing a String 题意:给定一个2*n(n<=20)的字符串及每个位置的字符包含的权重,求将该字符串分成两个子序列S1.T1,要求S1=T1且abs(weight1- ...
- POJ2112_Optimal Milking(网洛流最大流Dinic+最短路Flody+二分)
解题报告 农场有k个挤奶机和c头牛,每头牛到每一台挤奶机距离不一样,每台挤奶机每天最多挤m头牛的奶. 寻找一个方案,安排每头牛到某一挤奶机挤奶,使得c头牛须要走的全部路程中的最大路程的最小值. 要使每 ...
- POJ2828 Buy Tickets 【线段树】+【单点更新】+【逆序】
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 12296 Accepted: 6071 Desc ...
- nginx源代码分析--高性能server开发 常见的流程模型
1.高性能server 对于高性能server对于.处理速度和占用空间小是典型特性.特别是当server经验C10K问题的时候(网络server在处理数以万计的client连接时.往往出现效率低下甚至 ...
- 承载于以太网帧之上的数据包的解析——ARP、IPv4、IPv6
承接上一博文而来,继续解析网络数据包,对于承载在以太网上的三种协议进行了解析,主要是分为依据RFC定义的标准先解析头部数据,然后得到有效载荷,即为协议包括的实体数据,更上层进行进一步处理. 一.ARP ...