Android 自定义旋转进度框(单帧)
2013-05-14 20:11
176 查看
1.对话框布局文件
2.工具类创建对话框
说明:创建旋转动画时,将动画结束时的角度设置为359度,以防止动画停顿现象
3.对话框样式
4.使用对话框
此时当需要使用对话框时,只需通过工具类实例化一个对话框即可:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <ImageView android:id="@+id/loadingDialog_bg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/loding_dialog"/> </LinearLayout>
2.工具类创建对话框
public class LoadingDialog { public static Dialog createLoadingDialog(Context context) { LayoutInflater mInflater = LayoutInflater.from(context); LinearLayout layout = (LinearLayout) mInflater.inflate(R.layout.loading_dialog, null); ImageView image = (ImageView) layout.findViewById(R.id.loadingDialog_bg); //创建动画 Animation animation = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); LinearInterpolator interpolator = new LinearInterpolator(); //匀速旋转 animation.setInterpolator(interpolator); animation.setDuration(2000); //一次动画耗时2000ms animation.setRepeatCount(-1); //重复播放动画 //显示动画 image.startAnimation(animation); //创建对话框 Dialog loadingDialog = new Dialog(context,R.style.dialog); loadingDialog.setContentView(layout); return loadingDialog; } }
说明:创建旋转动画时,将动画结束时的角度设置为359度,以防止动画停顿现象
3.对话框样式
<style name="dialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item><!--边框--> <item name="android:windowIsFloating">true</item><!--是否浮现在activity之上--> <item name="android:windowIsTranslucent">false</item><!--半透明--> <item name="android:windowNoTitle">true</item><!--无标题--> <item name="android:windowBackground">@color/transparent</item><!--背景透明--> <item name="android:backgroundDimEnabled">false</item><!--模糊--> </style>
4.使用对话框
此时当需要使用对话框时,只需通过工具类实例化一个对话框即可:
Dialog dialog = LoadingDialog.createLoadingDialog(LCCXActivity.this); dialog.show();
相关文章推荐
- Android 自定义圆形旋转进度条,仿微博头像加载效果
- Android 自定义View -- 圆形进度条,文字旋转
- android自定义控件之三角绕圆环旋转 +改变速度+改变颜色
- 【Android自定义view系列】圆形百分比进度条
- android的自定义camera竖屏时,摄像头自动旋转90度的解决方案
- Android自定义View-圆形加载进度条
- Android 自定义进度条
- Android view自定义实现动态进度条
- android 自定义 环形进度条
- android自定义圆形进度条
- Android自定义View实现多片叶子旋转滑动(五)
- Android自定义View实现叶子飘动旋转效果(四)
- Android高手进阶之自定义View,自定义属性(带进度的圆形进度条)
- Android 自定义绘制圆形进度条(扩展性强!)
- Android 自定义水平进度条Horizontal ProgressBar
- Android 高手进阶之自定义View,自定义属性(带进度的圆形进度条)
- Android编程基于自定义View实现绚丽的圆形进度条功能示例
- Android中自定义SeekBar的背景颜色,进度条颜色,以及滑块的图片
- Android 高手进阶之自定义View,自定义属性(带进度的圆形进度条)
- Android系列学习讲座之三--App自动更新之自定义进度视图和内部存储