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(); // 显示加载中对话框 |
转载请注明:迷路的老鼠 » android加载中对话框,循环,透明