Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bring progress bar in top of layout

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.

like image 948
Shamim Ahmad Avatar asked Aug 07 '17 13:08

Shamim Ahmad


People also ask

How to show ProgressBar in android?

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);

How do I center my progress bar?

Just change your Layout as RelativeLayout and add android:layout_centerInParent="true" to your ProgressBar. Save this answer.

How to set progress bar visible in android studio?

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.


1 Answers

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..

like image 75
Deepak Rana Avatar answered Oct 07 '22 01:10

Deepak Rana