Android开发加载数据的转圈动画

释放双眼,带上耳机,听听看~!

效果:(下面转圈的小圆圈)

private CustomProgressDialog progressDialog;
//实例化自定义CustomProgressDialog
progressDialog = new CustomProgressDialog(context, R.style.progressDialog);
//设置不可点击外边取消动画
progressDialog.setCanceledOnTouchOutside(false);
//动画显示
progressDialog.show();

 

样式:progressDialog
<style name="progressDialog" 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">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
<!-- 模糊 -->
<!-- <item name="android:windowContentOverlay">@null</item> -->
</style>
//自定义CustomProgressDialog
public class CustomProgressDialog extends ProgressDialog {
private Context context;
public CustomProgressDialog(Context context) {
super(context);
this.context = context;
}
public CustomProgressDialog(Context context, int theme) {
super(context, theme);
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = View.inflate(getContext(), R.layout.customprogressdialog, null);
ImageView progress_img = (ImageView)view. findViewById(R.id.iv_bg);
Animation operatingAnim = AnimationUtils.loadAnimation(getContext(), R.anim.anim_upload_progress);
//LinearInterpolator lin = new LinearInterpolator();
// operatingAnim.setInterpolator(lin);
progress_img.setAnimation(operatingAnim);
setContentView(view);
}
@Override
public void show() {
//setCancelable(false);;
super.show();
}
}

//布局:customprogressdialog

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="160dip"
android:layout_height="60dip"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:gravity="center"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical" >
//转圈的图片
<ImageView
android:id="@+id/iv_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/common_refresh" />
<TextView
android:layout_centerHorizontal="true"
android:layout_below="@id/iv_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="加载中...."
android:textSize="10dip"
android:layout_marginTop="15dip"
android:textColor="@android:color/darker_gray" />
</RelativeLayout>
</LinearLayout>

//动画:anim_upload_progress

//在正中心,在1秒内,从0度转到360度,不停止
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<rotate
android:duration="1000"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="-1"
android:toDegrees="360" />
</set>

人已赞赏
Android文章

Android开发异步调用websevice接口

2021-2-1 12:07:22

Android文章

Android开发Fresco使用PhotoDraweeView 实现图片的手势缩放

2021-2-1 13:01:09

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索