为什么ProgressBar在Android中交换布局时停止动画?

为什么ProgressBar在Android中交换布局时停止动画?,android,android-widget,android-layout,Android,Android Widget,Android Layout,我使用的是线性布局。它包括一个progressbar.xml,向用户显示等待的指示器。有两个按钮显示“abc”和“xyz”。当前“abc”按钮处于按下状态时。当活动开始时,它会向用户显示进度条(进度条通过此属性处于动画状态:android:indeterminate=“true”)。用户单击“xyz”按钮。我通过findViewById(int-id)存储进度条布局的引用;然后使用LayoutInflater对另一个data.xml表单布局进行充气。我删除mainLinearview.remov

我使用的是线性布局。它包括一个progressbar.xml,向用户显示等待的指示器。有两个按钮显示“abc”和“xyz”。当前“abc”按钮处于按下状态时。当活动开始时,它会向用户显示进度条(进度条通过此属性处于动画状态:android:indeterminate=“true”)。用户单击“xyz”按钮。我通过findViewById(int-id)存储进度条布局的引用;然后使用LayoutInflater对另一个data.xml表单布局进行充气。我删除mainLinearview.removeAllView(); 然后添加mainLinearview.addView(dataview); 并显示其他数据。当用户再次单击“abc”按钮时,相同的步骤将应用于mainLinearview.addView(progressbar)

主要问题是这次progressbar没有设置动画您能帮忙吗?我还搜索了如何更改progressbar的颜色。但我没有发现什么好东西。提前谢谢


首先,发布代码将帮助您获得帮助。听起来您没有正确编辑清单文件以实际显示ProgressBar,所以请先发布它的外观。这相当简单


检查您的活动类…您是否已将可见性设置为true?

我也遇到了同样的问题,但我正在将一个按钮与不确定的进度条交换,因此我查看了一下,他们对不确定的进度条使用了
startAnimation()
stopAnimation()
,但是这些方法对于活动是不可见的,所以我使用的快速解决方法是在
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);
}
通过视图传递的
当前是一个不确定的进度条,单击按钮后按钮将被替换,并在后台处理完成后恢复


希望在进度条再次出现并且应该再次设置动画时调用此选项会有所帮助

public static void resumeProgressBarAnimation(ProgressBar pb) {
    if (pb.getVisibility() == View.VISIBLE) {
        pb.setVisibility(View.INVISIBLE);
        pb.setVisibility(View.VISIBLE);
    }
}