如何确保进度条已停止

3
我知道要“停止”ProgressBar,需要将其可见性设置为View.GONE。但是...那真的会停止吗?背景中有一个动画在播放,它会在检测到进度条为GONEINVISIBLE时停止动画吗?我真的不想让进度条在不需要时持续运行。这是浪费处理能力。

有人有什么想法吗?

1个回答

2

看了一下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后,它将停止动画。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接