android-animation - 长时间操作期间的微调动画

标签 android-animation android android-progressbar android-event

我的应用程序有一个不那么频繁的操作,它在 UI 线程上执行并且需要很长时间(最多 3 秒)。我想在那段时间显示动画“等待”指示。例如,旋转微调器。不需要显示实际进度,只是一个定速动画。

我创建了一个在长时间操作期间弹出的自定义对话框,它有这个布局

<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/spinner"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

问题是它不旋转。如何让它旋转,即使 UI 线程很忙?

我试图创建一个事件链来递增它,但我只收到两个事件,可能是因为 UI 线程很忙。

// In the custom dialog class. mProgressBar is the ProgressBar in the layout.
// Called externally once when the dialog is shown
public void tick() {
    mProgressBar.incrementProgressBy(10);
    mProgressBar.postDelayed(new Runnable() {
        @Override
        public void run() {
            // Not a recursion since it's done in a future event.
            tick();
        }
    }, 100);
}

实现这个动画的简单方法是什么?逐帧动画会更容易做吗?

最佳答案

使用 AsyncTask http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html它不是自旋,因为它在 UI 线程中执行

关于android-animation - 长时间操作期间的微调动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9876096/

相关文章:

android animatorset内存管理,从imageview中释放内存

android - ImageView放大动画截断图片

java - 如何在另一个 Activity 或主类的 Activity 中调用处理程序

android - ProgressDialog 已弃用。要使用的替代项是什么?

android - ActionBarSherlock 以编程方式设置水平进度条最大值

android - 圆形进度条内的圆形进度

android - 如何在整个翻译动画中实现均匀速度?

android - Google map 布局如何动画化?

android - android中的去电事件

java - 应用程序作为全局变量