它们的定义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>

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Android中关于dip和px以及转换的总结
我们在页面布局的时候,经常会设置容器的长度,但是到底该使用哪个作为长度的单位而懊恼。在Android中支持的描述大小区域的类型有以下几种:px(pixels)——像素:不同的设备显示效果相同,一般我们HVGA代表320x480像素,这个用的比较多。dip(device independent pixels)——设备独立像素:这个和设备硬件有关,一般我们为了支持WCGA、HVGA和QVGA推荐使用这个,不依赖于像素。等同于dp。sp(scaled pixels—best for text size)——主要用于字体显示best for textsize。由此,根据 google 的建议,TextView 的字号最好使用 sp 做单位,而且查看TextView的源码可知 Android 默认使用 sp 作为字号单位。pt(points)——磅:是一个标准的长度单位,1pt=1/72英寸,用于印刷业,非常简单易用; 在 Android 中,1pt 大概等于2.22sp以上供参考,如果 UI 能够以sp为单位提供设计是最好的,如果设计中没有sp的概念,则开发人员也可以通过适当的换算取近似值。i...
- 下一篇
在Android中调用WebService
某些情况下我们可能需要与Mysql或者Oracle数据库进行数据交互,有些朋友的第一反应就是直接在Android中加载驱动然后进行数据的增删改查。我个人不推荐这种做法,一是手机毕竟不是电脑,操作大量数据费时费电;二是流量贵如金那。我个人比较推荐的做法是使用Java或PHP等开发接口或者编写WebService进行数据库的增删该查,然后Android调用接口或者WebService进行数据的交互。本文就给大家讲解在Android中如何调用远程服务器端提供的WebService。 既然是调用WebService,我们首先的搭建WebService服务器。为了便于操作,我们就使用网上免费的WebService进行学习。 地址:http://www.webxml.com.cn/zh_cn/index.aspx 下面演示的就是如何通过该网站提供的手机号码归属地查询WebService服务查询号码归属地 调用地址http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?op=getMobileCodeInfo。 首先,将请求消息保存...
相关文章
文章评论
共有0条评论来说两句吧...