Search code examples
androidlayoutswipeandroid-progressbarinvisible

Android progressbar in swipe layout invisible


In one layout file I want show a progressbar and a swipeable webview. If I implement the swipe layout the progressbar disappears automatically and can't be shown.

What's the problem?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:mlns="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.xy.MainActivity">

    <ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBarCenter"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:visibility="visible"
    android:background="#ff0303" />

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:mlns="http://schemas.android.com/apk/res-auto"
    android:id="@+id/swiper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.xy.MainActivity">

    <WebView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/webView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>

Solution

  • It is because SwipeRefreshLayout is covering ProgressBar. In RelativeLayout, the one at lower down in the Xml means higher up in the Z-axis.

    Reverse the order should work.

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:mlns="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.xy.MainActivity">
    
        <android.support.v4.widget.SwipeRefreshLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            xmlns:mlns="http://schemas.android.com/apk/res-auto"
            android:id="@+id/swiper"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.xy.MainActivity">
    
            <WebView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/webView"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />
        </android.support.v4.widget.SwipeRefreshLayout>
    
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/progressBarCenter"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:visibility="visible"
            android:background="#ff0303" />
    </RelativeLayout>