您的位置:首页 > 移动开发 > Android开发

Android 自定义旋转进度框(单帧)

2013-05-14 20:11 176 查看
1.对话框布局文件

<?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 动画 对话框