Android - ProgressBar setVisibility to GONE not working

后端 未结 5 2378
无人及你
无人及你 2021-02-20 08:59

I\'ve been adding a ProgressBar to the fragments in my app. I\'ve set it up to the two main fragments (used as tabs) as follows:

ProgressBar in

相关标签:
5条回答
  • 2021-02-20 09:36

    It's probably due the fact that View.GONE will prevent the View from being drawn to the screen, while another View android:layout_align[POSITION] component may be defined to that View, so their position can't be calculated.

    View.INVISIBLE will work cause it just make it invisible, but the View is still there and other View can calculate their position if the align is set to it

    0 讨论(0)
  • 2021-02-20 09:44

    This work for me:

    rootView.findViewById(R.id.progress_bar).setVisibility(View.GONE);
    
    0 讨论(0)
  • 2021-02-20 09:50

    Check this code:

    spinner = (ProgressBar)getActivity().findViewById(R.id.progressBar1);
    

    If you are using fragments it should be like this:

    spinner = (ProgressBar)viewIinflated.findViewById(R.id.progressBar1);//same case with dialogs
    

    If you are using activity then:

    spinner = (ProgressBar)findViewById(R.id.progressBar1);
    
    0 讨论(0)
  • 2021-02-20 09:52

    I had a same issue (progressBar.setVisibility() was not working).

    As @Illegal Argument said,

    // in Activity
    ProgressBar mProgressBar = (ProgressBar)findViewById(R.id.progressBar1);
    mProgressBar.setVisibility(View.GONE); 
    

    should be working, if that code runs on uiThread(mainThread).

    My problem was that I was trying to run the code not on uiThread. So I solved the issue by changing code from

    mProgressBar.setVisibility(View.GONE);
    

    to

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mProgressBar.setVisibility(View.GONE);
        }
    });
    
    0 讨论(0)
  • 2021-02-20 09:52

    progressBar.setVisibility(ProgressBar.VISIBLE);

    0 讨论(0)
提交回复
热议问题