【问题标题】:How to be sure Progress Bar is stopped如何确保进度条已停止
【发布时间】:2023-03-28 02:52:02
【问题描述】:

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

有人知道吗?

【问题讨论】:

    标签: android android-progressbar


    【解决方案1】:

    看着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 隐藏后会停止动画。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      • 2018-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多