I have included a progress bar in my relative layout, but it is running behind the layout. Is there any way I can bring it in front show that it show when the page is loading.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/pageBackgroundColor"
android:gravity="center"
tools:context="co.sd.app.CheckoutActivity">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="visible" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/relativeLayout"
android:layout_marginLeft="@dimen/page_marging_left"
android:layout_marginRight="@dimen/page_marging_right">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/service_detail_cv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/shedule_apt_cv"
android:layout_marginBottom="@dimen/dim_10sp"
android:layout_marginTop="@dimen/dim_10sp"
android:textColor="@color/darkGrey" />
</RelativeLayout>
</RelativeLayout>
I have no idea why is it show like this.
In android there is a class called ProgressDialog that allows you to create progress bar. In order to do this, you need to instantiate an object of this class. Its syntax is. ProgressDialog progress = new ProgressDialog(this);
Just change your Layout as RelativeLayout and add android:layout_centerInParent="true" to your ProgressBar. Save this answer.
In this step we open MainActivity where we add the code to initiate the progress bar & button and then perform click event on button which display the progress bar. Output: Now start the AVD in Emulator and run the App. Click on the start button and Progress Bar will be displayed on screen.
use this code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/pageBackgroundColor"
android:gravity="center"
tools:context="co.sd.app.CheckoutActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/relativeLayout"
android:layout_marginLeft="@dimen/page_marging_left"
android:layout_marginRight="@dimen/page_marging_right">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/service_detail_cv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/shedule_apt_cv"
android:layout_marginBottom="@dimen/dim_10sp"
android:layout_marginTop="@dimen/dim_10sp"
android:textColor="@color/darkGrey" />
</RelativeLayout>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="visible" />
</RelativeLayout>
Hope this will help you out..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With