我知道,要 "停止 "进度条,需要将其可见性设置为 View.GONE
. 但是......这样真的就停止了吗?后台有一个动画,会对视图进行动画处理。一旦它检测到进度条是在进行中,这个动画就会停止吗?GONE
或 INVISIBILE
? 我真的不想让一个进度条在后台持续运行,在不需要的时候。这是一种处理能力的浪费。
有人有什么办法吗?
观察 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
在你隐藏它之后,将停止动画。