最新消息:从今天开始,做一个有好习惯的人。

android加载中对话框,循环,透明

其他 迷路的老鼠 2618浏览 2评论

1、自定义对话框

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public class HkDialogLoading extends Dialog {
Context context;

ImageView vLoading; // 圆型进度条
Animation anim;// 动画

public HkDialogLoading(Context context) {
super(context, R.style.HKDialogLoading);
this.context = context;
}

public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
requestWindowFeature(Window.PROGRESS_VISIBILITY_ON);
super.onCreate(savedInstanceState);

anim = AnimationUtils.loadAnimation(this.getContext(),
R.anim.rotate_repeat);
anim.setInterpolator(new LinearInterpolator());

vLoading = new ImageView(context);
vLoading.setImageResource(R.drawable.loading_icon);// 加载中的图片,建议圆形的

// 布局
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER;

addContentView(vLoading, lp);

setCanceledOnTouchOutside(false);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// 按下了键盘上返回按钮
this.hide();
return true;
}
return false;
}

@Override
public void show() {
super.show();
vLoading.startAnimation(anim);
}
}

2、用到的动画文件rotate_repeat (在res/anim目录下面建文件rotate_repeat.xml)

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="utf-8"?>;
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" >
<rotate
android:duration="1000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="100"
android:repeatMode="restart"
android:toDegrees="360" />
</set>

3、用的到的样式文件 (在res/values目录下的style.xml文件中的<resources>节点下添加下面的代码)

1
2
3
4
5
6
7
<style name="HKDialogLoading" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>

4、调用

1
2
dialogLoading = new HKDialogLoading(this);
dialogLoading.show(); // 显示加载中对话框

1

转载请注明:迷路的老鼠 » android加载中对话框,循环,透明

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (2)

  1. 不明觉厉,只好点赞~
    wa11年前 (2014-05-25)回复
    • 一个不明真相的群众
      admin11年前 (2014-05-27)回复