Why does the ProgressBar stop the animation when replacing the layout in Android?

I am using linear layout. This includes progressbar.xml, which shows an indicator for user expectation. There are two buttons that say "abc" and "xyz". If the "abc" button is currently pressed. When the action starts, a progress bar is displayed (the progress indicator is in the animation for this property android: indeterminate = "true")for the user. Click the "xyz" button. I keep a reference to the execution run layout using findViewById (int id); And then INFLATE using LayoutInflater, another format for the data.xml form. I delete mainLinearview.removeAllView (); Then add mainLinearview.addView (dataview); And it displays other data. After the user clicks the "abc" button, the same step applies to mainLinearview.addView (progressbar).

The main problem is that this progress does not revive . Help me please? One more thing I'm looking for how to change the color of a progressbar. But I did not find anything good. Thanks in advance.

+3
source share
3 answers

, , .

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

, Button ProgressBar, ProgressBar, 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);
}

with ProgressBar, OnClick , .

,

+1

Firstly, posting a code will help you get help. It looks like you have incorrectly edited the manifest file to actually display the ProgressBar, so start by posting what it looks like. It is pretty simple.

Test your activity class ... have you set visibility as true?

0
source

Source: https://habr.com/ru/post/1782409/


All Articles