如何确定进度条已停止

How to be sure Progress Bar is stopped

我知道要 "stop" ProgressBar 需要将其可见性设置为 View.GONE。但是……真的能阻止吗?背景中有一个动画可以使视图动画化。一旦检测到进度条是 GONEINVISIBILE,动画是否停止?我真的不想在不需要的时候在后台连续 运行 有一个进度条。这是对处理能力的浪费。

有人知道吗?

查看 ProgressBar.java 我发现:

/**
 * Returns whether the ProgressBar is animating or not. This is essentially the same
 * as whether the ProgressBar is {@link #isIndeterminate() indeterminate} and visible,
 * as indeterminate ProgressBars are always animating, and non-indeterminate
 * ProgressBars are not animating.
 *
 * @return true if the ProgressBar is animating, false otherwise.
 */
public boolean isAnimating() {
    return isIndeterminate() && getWindowVisibility() == VISIBLE && isShown();
}

void startAnimation() {
    if (getVisibility() != VISIBLE || getWindowVisibility() != VISIBLE) {
        return;
    }
    ...


@Override
protected void onDetachedFromWindow() {
    if (mIndeterminate) {
        stopAnimation();
    }
    ...

我想,ProgressBar 隐藏后会停止动画。