当前位置: 代码迷 >> Android >> android开发稳扎稳打之52:AsyncTask处理过程中自定义旋转的菊花
  详细解决方案

android开发稳扎稳打之52:AsyncTask处理过程中自定义旋转的菊花

热度:48   发布时间:2016-04-28 02:51:10.0
android开发步步为营之52:AsyncTask处理过程中自定义旋转的菊花


AsyncTask在处理过程中,我们一般会使用一个转动的“菊花”来显示提示当前用户当前的进度,一般呢,我们都不会用系统自带的ProgressDialog,而是自己设计个动画来实现,菊花转动时,不允许用户点击页面,那么把这个菊花放在AlertDialog自定义的页面上,如果转动过程中,允许用户点击页面其他位置,比如搜索城市,那么把这个进度图片直接放在该页面的xml文件上就可以了。给出转动的菊花实现代码 : )

    第一步:动画anim文件下新增rotate_animation.xml

<?xml version="1.0" encoding="utf-8"?>

<rotate xmlns:android="http://schemas.android.com/apk/res/android" 

    android:pivotX="50%" android:pivotY="50%" 

    android:fromDegrees="0" android:toDegrees="-720"

    android:duration="1800"

    android:fillAfter="true"

    android:interpolator="@android:anim/linear_interpolator"

    >

</rotate>

    

    第二步:给imageview设置动画

    private void startAnimation(View view) {

        Animation animation = AnimationUtils.loadAnimation(CitySettingActivity.this, R.anim.rotate_animation);

        animation.setRepeatCount(Animation.INFINITE);

        animation.setRepeatMode(Animation.RESTART);

        view.startAnimation(animation);

}

    第三步:AsyncTask中添加转动菊花

onPreExecute()里面

打开动画

startAnimation(imgProgress);

onPostExecute()里面

关闭动画

imgProgress.clearAnimation();

  相关解决方案