【问题标题】:Why ProgressBar stop animation While Swapping the Layout in Android?为什么 ProgressBar 在 Android 中交换布局时会停止动画?
【发布时间】:2010-12-28 07:11:58
【问题描述】:
我使用的是线性布局。其中包括一个progressbar.xml,它向用户显示等待的指示器。有 2 个按钮,上面写着“abc”和“xyz”。当前“abc”按钮处于按下状态时。当活动开始时,它会向用户显示进度条 (进度条在动画中通过此属性 android:indeterminate="true") 显示给用户。用户单击“xyz”按钮。我通过 findViewById(int id); 存储进度条布局的引用;然后使用 LayoutInflater 进行 INFLATE 另一个 data.xml 表单布局。我删除 mainLinearview.removeAllView();
然后添加 mainLinearview.addView(dataview);
并显示其他数据。再次,当用户单击“abc”按钮时,相同的步骤将应用于 mainLinearview.addView(progressbar)。
主要问题是这次进度条没有动画你能帮忙吗?我搜索了如何更改进度条颜色的另外 1 件事。但是我没有发现任何好的东西。提前致谢。
【问题讨论】:
标签:
android
android-widget
android-layout
【解决方案1】:
当进度条再次出现并且它应该再次动画时调用它。
public static void resumeProgressBarAnimation(ProgressBar pb) {
if (pb.getVisibility() == View.VISIBLE) {
pb.setVisibility(View.INVISIBLE);
pb.setVisibility(View.VISIBLE);
}
}
【解决方案2】:
我遇到了同样的问题,但是我正在用一个不确定的 ProgressBar 交换一个 Button,所以我查看了 ProgressBar source,他们使用 startAnimation() 和 stopAnimation() 来表示不确定的 ProgressBar,但是这些方法对于Activity 所以我使用的快速解决方法是在setVisibility(int) 他们根据 ProgressBar 的可见性状态启动和停止动画,但关键是您必须在更改布局之前停止动画并在ProgressBar 父布局回来了......所以最后我做的是:
/**
* Replace a button with the specified view. The view will be set
* with the button layout parameters. Use {@link #revert(HeaderButton, View)}
* to rollback this operation
* @param button
* @param with
*/
public void replace(HeaderButton button, View with){
with.setVisibility(View.VISIBLE);
mHeaderView.replace(button, with);
}
/**
* Restores a button that was previously replaced
* @param button
* @param with
*/
public void revert(HeaderButton button, View with){
with.setVisibility(View.GONE);
mHeaderView.revert(button, with);
}
传递的withView当前是一个不确定的ProgressBar,按钮被替换为OnClick,当后台进程完成后恢复。
希望对你有帮助
【解决方案3】:
首先,发布您的代码将帮助您获得帮助。听起来您没有正确编辑清单文件以实际显示 ProgressBar,因此请从发布它的样子开始。这很简单。
检查您的 Activity 类...您是否将可见性设置为 true?