Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set android progress bar in center of the screen

I am trying to show the progress bar in the center of the screen, but it doesn't show up in the center. Below is my layout. What am i doing wrong here? Basically this is a layout to show image and android gallery widget on top. When the user clicks on the thumbnails, I am loading an image from the web and I want to show the progress dialog while the image is loading.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/container" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical">

    <Gallery android:id="@+id/gallery" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:gravity="top" />

    <ImageView android:id="@+id/actualimage" android:scaleType="fitCenter"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:visibility="gone" android:layout_gravity="center_vertical|center_horizontal|center"
        android:adjustViewBounds="true" />

    <ProgressBar android:id="@+android:id/progress_small1"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:visibility="visible" android:layout_gravity="center_vertical|center_horizontal"
        android:gravity="center_vertical|center_horizontal" />

</LinearLayout>
like image 360
Chandu Avatar asked Oct 24 '11 04:10

Chandu


People also ask

How do I center my android progress bar?

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

How do you center a progress bar?

You can wrap the <progress> in a <div> whose 'align' attribute set to "center".

How do I customize my progress bar?

Customizing a ProgressBar requires defining the attribute or properties for the background and progress of your progress bar. You can do this in the XML file or in the Activity (at run time). Why is it necessary to set the progress drawable at runtime, when it is possible to do it on the xml file?


1 Answers

Using a LinearLayout will stack your views vertically. Right now, your ImageView and ProgressBar are fighting for the centered position. For this type of situation, I would definitely recommend a RelativeLayout.

With RelativeLayout, you use android:layout_centerInParent="true".

like image 66
Paul Burke Avatar answered Nov 08 '22 13:11

Paul Burke