Android progressBar not showing

后端 未结 3 1203
無奈伤痛
無奈伤痛 2021-02-13 14:28

I have a progressbar that is supposed to run in an AsyncTask , but it is not appearing, although the task runs

XML:



        
相关标签:
3条回答
  • 2021-02-13 15:09

    Did you forget to execute your task?

      ...
      diagProgress = (ProgressBar)findViewById(R.id.progressBar1);
      new DiagnosticsTask().execute();
    
    
      ....
    
    0 讨论(0)
  • 2021-02-13 15:16

    I had that issue when I forgot to turn on animations after testing xD

    0 讨论(0)
  • 2021-02-13 15:23

    Try this replace your ProgressBar with the one below.

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:indeterminate="true"
        />
    

    Let me know if it works, I would explain the rationale.

    Rationale: Now I am putting your code below for ProgressBar

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="200dip"
        android:layout_height="200dip"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:indeterminate="true"
        android:paddingBottom="450dip"
        />
    

    RelativeLayout allows you Z-ordering. So since you needed ProgressBar on top you need not do the kind of manipulations you are doing.

    android:layout_alignParentBottom="true"  
    

    This sets the Progress Bar at the botton of the layout:

    android:paddingBottom="450dip" android:layout_width="200dip" android:layout_height="200dip"
    

    All the three values here are absolute which is a strict no-no as far as Android is concerned. Most Likely your paddingBottom was pushing your ProgressBar out of View. As your padding is greater than the actual width/height of the control

    As a thumb rule always use relative values for it to work on all the devices and form factors.

    Let me know if this makes sense.

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