它们的定义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(分类) ...
随机推荐
- 【Visual C++】Windows GDI贴图闪烁解决方法
一般的windows 复杂的界面需要使用多层窗口而且要用贴图来美化,所以不可避免在窗口移动或者改变大小的时候出现闪烁. 先来谈谈闪烁产生的原因 原因一:如果熟悉显卡原理的话,调用GDI函数向屏幕输出的 ...
- HttpSession具体解释
session的机制 http是无状态的协议,客户每次读取web页面时,server都打开新的会话,并且server也不会自己主动维护客户的上下文信息,那么要怎么才干实现会话跟踪呢?session就是 ...
- AIR
There is a meaning for wings that cannot fly,it's a previous memory of when you once flew through th ...
- DOM4J解析XML文档
Tip:DOM4J解析XML文档 Dom4j是一个简单.灵活的开放源代码的库.Dom4j是由早期开发JDOM的人分离出来而后独立开发的.与JDOM不同的是,dom4j使用接口和抽象基类,虽然Dom4j ...
- EasyUI初体验--右键弹框
在C/S中可能非常easy实现右键弹框,但在B/S中直到今天我才搞定,小小得瑟一下.只一个html页面,导入相关的Easy-UI类库就能搞定,Easy-UI类库下载地址 <!DOCTYPE ht ...
- Free Mind » Blog Archive » Yakuake + dtach vs Screen + urxvt
Free Mind » Blog Archive » Yakuake + dtach vs Screen + urxvt Yakuake + dtach vs Screen + urxvt
- Oracle Enterprise Manager Cloud Control 12c R4 安装配置
准备软件 em12.1.0.4_linux64_V45344-01.zip em12.1.0.4_linux64_V45345-01.zip em12.1.0.4_linux64_V45346-01. ...
- GitHub上最火的74个Android开源项目
GitHub上最火的74个Android开源项目 1.ActionBarSherlock ActionBarSherlock应该算得上是GitHub上最火的Android开源项目了,它是一个独立的库, ...
- ym——Android开发编码规范(自用)
转载请注明本文出自Cym的博客(http://blog.csdn.net/cym492224103),谢谢支持! Android开发编码规范 目的及指导原则 目的 统一规范 Eclipse编辑环境下J ...
- python 入门学习---模块导入三种方式及中文凝视
Python 有三种模块导入函数 1. 使用import 导入模块 import modname : 模块是指一个能够交互使用,或者从还有一Python 程序訪问的代码段.仅仅要导入了一个模块,就能够 ...