Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ProgressBar .xml Layout

I have this for an XML file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ProgressBar
        android:id="@+id/progressbar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:visibility="visible" />

    <WebView
        android:id="@+id/web_engine"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="gone" />

</LinearLayout>

And I want the ProgressBar to be the Large style, and be centered in the middle of the screen vertically and horizontally... When I set layout_width and height to fill_parent, it increases the size of the actual loading spinner to the entire screen... How can I make the layout fit the entire screen and center the actual loading icon?

like image 224
tcd Avatar asked Sep 05 '12 22:09

tcd


People also ask

How do I make my progress bar horizontal android?

In Android, by default a progress bar will be displayed as a spinning wheel but If we want it to be displayed as a horizontal bar then we need to use style attribute as horizontal. It mainly use the “android. widget. ProgressBar” class.

How do I change the progress bar icon on android?

Go to the activity_main. xml file and refer to the following code. Open the activity_main. xml file and in the ProgressBar tag and set the drawable in indeterminateDrawable attribute.

How do I stop indeterminate progress bar?

An indeterminate progress bar animates constantly. You can stop the animation and clear the progress bar by making the progress bar determinate and setting the current value to the minimum. For example: pb.


2 Answers

I have checked few possibilities and in my experience the best option for such task is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ProgressBar
        android:id="@+id/progressbar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="visible" />

    <WebView
        android:id="@+id/web_engine"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"       
        android:visibility="gone" />

</RelativeLayout>

I am using RelativeLayout with android:layout_centerInParent="true" which works better than LinearLayout.

Cheers

like image 122
Michal Avatar answered Oct 15 '22 02:10

Michal


You can also use FrameLayout insetad of LinearLayout. That way visible view will overlap invisible one. I revised you code:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<ProgressBar
    android:id="@+id/progressbar"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical|center_horizontal"
    android:visibility="visible" />

<WebView
    android:id="@+id/web_engine"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:visibility="gone" />

</FrameLayout>
like image 44
Marcin S. Avatar answered Oct 15 '22 02:10

Marcin S.