Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 5.0 - ProgressBar cannot be displayed over a Button

I think the title is pretty explicit about my problem... So here is my layout :

            <RelativeLayout                 android:layout_width="wrap_content"                 android:layout_height="wrap_content">                  <Button                     android:id="@+id/button_action"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:text="Login" />                  <ProgressBar                     android:id="@+id/progress_bar"                     android:layout_width="50dp"                     android:layout_height="50dp"                     android:layout_centerInParent="true"/>              </RelativeLayout> 

On android SDKs < 21, no problem, the ProgressBar is correctly displayed over the Button and centered in the Button. But on Android 5.0, the ProgressBar is displayed behind the Button.

So you can see it's correctly positionned it when you activate the option "Show layout bounds" in Developer Options settings, but you can't see anything on the screen without that option.

Would anybody know how to fix this? I guess it's a matter of elevation recently introduced, but I really don't know how to take care of it. For the record, I'm using the recently released Theme.AppCompat style from the support.v7.

EDIT:

I also tried to apply setElevation(0) and setTranslationY(0) to the Button programmatically but it didn't change anything. So I wonder if it has to deal with the elevation.

like image 622
MathieuMaree Avatar asked Oct 23 '14 08:10

MathieuMaree


People also ask

What is progress bar in Android?

So let’s see what is Android Progress Bar. Progress bar is a user interface control that shows the progress of any operation. The operation includes downloading a file, copying a file or moving a file. It is like a graphical representation of an indicator that shows the progress of some process or operation.

What is the difference between progress and progresstint in Android?

android: progress – It sets the default progress of the progress bar, which can be set from 0 to max. android:interpolar – It is used to set an acceleration curve for the indeterminate progress bars. android: min – It defines the minimum value for the progress bar. android: progressTint – It applies Tint on progress indicator in the progress bar.

Why is my ProgressBar not on top of the screen?

So since you needed ProgressBar on top you need not do the kind of manipulations you are doing. 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

What is Max and Min in Android progress bar?

android: max – It sets the maximum value of the progress bar. android: progress – It sets the default progress of the progress bar, which can be set from 0 to max. android:interpolar – It is used to set an acceleration curve for the indeterminate progress bars. android: min – It defines the minimum value for the progress bar.


1 Answers

You can add the android:translationZ attribute to the ProgressBar:

<ProgressBar     android:id="@+id/progress_bar"     android:layout_width="50dp"     android:layout_height="50dp"     android:translationZ="2dp"     android:layout_centerInParent="true"/> 
like image 190
wpiwonski Avatar answered Oct 10 '22 22:10

wpiwonski