1、自定义对话框 public class HKDialogLoading extends Dialog { Context context; public HKDialogLoading(Context context, int theme) { super(context, theme); this.context = context; ini(); } public HKDialogLoading(Context context) { super(context); this.context = context; ini(); } void ini() { /** * "加载项"布局,此布局被添加到ListView的Footer中。 */ LinearLayout contentView = new LinearLayout(context); contentView.setMinimumHeight(60); contentView.setGravity(Gravity.CENTER); contentView.setOrientation(LinearLayout.HORIZONTAL); /** * 向"加载项"布局中添加一个圆型进度条。 */ ImageView image = new ImageView(context); image.setImageResource(R.drawable.loading_icon); Animation anim = AnimationUtils.loadAnimation(context, R.anim.rotate_repeat); LinearInterpolator lir = new LinearInterpolator(); anim.setInterpolator(lir); image.setAnimation(anim); contentView.addView(image); setContentView(contentView); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // 按下键盘上返回按钮 if (keyCode == KeyEvent.KEYCODE_BACK) { this.dismiss(); } return true; } } 2、用到的动画文件rotate_repeat <?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、用的到的样式文件 <style name="HKDialog" 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、调用 dialogLoading = new HKDialogLoading(this, R.style.HKDialog); dialogLoading.show(); // 显示加载中对话框
http://zheyiw.iteye.com/blog/1546292
时间: 2024-11-05 12:13:22