2

I read two articles about this topic, this and this.

But both tell solutions like changing the elevation or translations.

The question is about bringing a Progress bar in front of a button in older versions that don't support elevation or translation attributes.

How can I do this in XML and in Java?!

Or it is not valid.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.business.abdelhafiz.omar.civiltaif.LoginActivity">

    <ImageView
        android:src="@drawable/home_civil"
        android:scaleType="fitXY"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ProgressBar
        android:id="@+id/login_progressbar"
        android:layout_centerInParent="true"
        android:layout_width="@dimen/image_height"
        android:layout_height="@dimen/image_height" />

    <Button
        android:id="@+id/login_email"
        android:layout_centerInParent="true"
        android:text="@string/login_email"
        android:onClick="loginEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/login_anonymous"
        android:layout_centerInParent="true"
        android:layout_below="@id/login_email"
        android:text="@string/login_anonymous"
        android:onClick="loginAnonymous"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

Here is a screen shot

enter image description here

I want to bring the progress bar in front of the buttons

Edit:

Nothing worked for me so I will just hide the buttons when I need to show the progress bar.

Thanks for your help.

Farhana Naaz Ansari
  • 7,524
  • 26
  • 65
  • 105
Android Admirer
  • 2,310
  • 2
  • 17
  • 38
  • This worked for me https://stackoverflow.com/questions/31343213/progressbar-on-top-of-button-in-relative-layout-issue-in-android-studio/31343665 – shashank chandak Jun 17 '18 at 15:03

4 Answers4

5

you can move it to the bottom like this

<ImageView
    android:src="@drawable/home_civil"
    android:scaleType="fitXY"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<Button
    android:id="@+id/login_email"
    android:layout_centerInParent="true"
    android:text="@string/login_email"
    android:onClick="loginEmail"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/login_anonymous"
    android:layout_centerInParent="true"
    android:layout_below="@id/login_email"
    android:text="@string/login_anonymous"
    android:onClick="loginAnonymous"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<ProgressBar
    android:id="@+id/login_progressbar"
    android:layout_centerInParent="true"
    android:layout_width="@dimen/image_height"
    android:layout_height="@dimen/image_height" />

or in onCreate method just write login_progressbar.bringToFront();

Vasileios Pallas
  • 4,801
  • 4
  • 33
  • 50
4

enter image description hereHere the solution, i just change the order of my elements

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
 tools:context="com.business.abdelhafiz.omar.civiltaif.LoginActivity">
<ImageView
    android:src="@drawable/home_civil"
    android:scaleType="fitXY"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<Button
    android:id="@+id/login_email"
    android:layout_centerInParent="true"
    android:text="@string/login_email"
    android:onClick="loginEmail"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/login_anonymous"
    android:layout_centerInParent="true"
    android:layout_below="@id/login_email"
    android:text="@string/login_anonymous"
    android:onClick="loginAnonymous"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />


<ProgressBar
    android:id="@+id/login_progressbar"
    android:layout_centerInParent="true"
    android:layout_width="@dimen/image_height"
    android:layout_height="@dimen/image_height" 
    android:background=""/>



</RelativeLayout>

i added background to progress to see that the progress is in front the buttons

Maryeme Alaoui
  • 93
  • 2
  • 13
1

Set an elevation on the ProgressBar; 2dp seems to work.

android:elevation="2dp"

You could also try setting translationZ as suggested in the accepted answer to a similar question.

I also came across this answer as an alternative.

0

For me the elevation on the ProgressBar needed to be 4dp, because the Button had already a 2dp elevation by design.

android:elevation="4dp"
Theseus
  • 33
  • 9