Get ViewSwitcher to match parent so that content can be centred

575 Views Asked by At

I am trying to make a layout containing a ViewSwitcher where the first view displayed is a spinning progress indicator in the centre of the screen, which then switches to a linear layout that will have content added to it once it is loaded.

The problem is that I want the spinning indicator to be in the centre so I set everything to match_parent so that it can be centred on the screen. However, this doesn't work and it gives me the warning:

This ViewSwitcher should use android:layout_height="wrap_content"

The layout is then displayed as if it were set to wrap_content. How can I fix this so that the spinning indicator is displayed in the centre of the screen?

Thanks.

My code:

<LinearLayout 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"
    android:background="#FFF"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/svXorBox"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ViewSwitcher
            android:id="@+id/vsCollection"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:id="@+id/llBusy"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center" >

                <ProgressBar
                    android:id="@+id/progressBar1"
                    style="?android:attr/progressBarStyleLarge"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/llCollection"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
            </LinearLayout>
        </ViewSwitcher>
    </ScrollView>

</LinearLayout>
0

There are 0 best solutions below