Android progressbar not showing

I have a progressbar that should start in AsyncTask, but it does not appear, although the task is running

XML:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/splashportrait"> <ProgressBar android:layout_alignParentBottom="true" android:indeterminate="true" android:layout_centerHorizontal="true" android:paddingBottom="450dip" android:layout_width="200dip" android:layout_height="200dip" android:id="@+id/progressBar1"></ProgressBar> </RelativeLayout> 

CODE:

 ProgressBar diagProgress; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splashscreen); diagProgress = (ProgressBar)findViewById(R.id.progressBar1); DiagnosticsTask diag = new DiagnosticsTask(); diag.execute(); /**rest of class ommitted here**/ } private class DiagnosticsTask extends AsyncTask<String, String, Boolean> { //Show spinner protected void onPreExecute() { //dialog.setMessage("Loading corresponding destinations..."); //dialog.show(); diagProgress.setVisibility(View.VISIBLE); diagProgress.showContextMenu(); Log.e("AsyncStatus", "spinner shown"); } /*other parts of the thread ommitted here*/ } 
+7
source share
3 answers

Try this by replacing your ProgressBar with the one below.

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

Let me know if this works, I will explain the rationale.

Rationale: Now I put your code below for the ProgressBar

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

RelativeLayout allows you to Z-order. Therefore, since you need a ProgressBar from above, you do not need to do the manipulations that you do.

 android:layout_alignParentBottom="true" 

This sets the progress bar at the template level:

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

All three values ​​here are absolute, which is strict, but not like Android. Most likely your paddingBottom was pushing your ProgressBar out of the view. Since your padding is larger than the actual width / height of the control

As a rule of thumb, always use relative values ​​to work on all devices and form factors.

Let me know if that makes sense.

+15
source

I had this problem when I forgot to enable animation after testing xD

+8
source

Did you forget to complete your task?

  ... diagProgress = (ProgressBar)findViewById(R.id.progressBar1); new DiagnosticsTask().execute(); .... 
0
source

All Articles