Can I use SwipeRefreshLayout inside DrawerLayout?

Both layouts are available in the Application Support Library.

I am not getting the desired result.

I have a DrawerLayout as root layout and then inside it one textual error view. and then SwipeRefreshLayout

This text view was visible when the root layout was FrameLayout. But since I changed the root layout to DrawerLayout the textview error never opens!

Am I using it correctly?

<android.support.v4.widget.DrawerLayout 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="@android:color/transparent"
    tools:context="com.timesbuzz.news.MainActivity"
    android:id="@+id/drawer_layout">

    <TextView
        android:id="@+id/errorView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:text="@string/error_view_text"
        android:textSize="30sp" />

    <ProgressBar
        android:id="@+id/loadingView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:indeterminate="true" />

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/contentView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- android.support.v4.view.ViewPager -->
        <fr.castorflex.android.verticalviewpager.VerticalViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.v4.widget.SwipeRefreshLayout>

    <!-- The navigation drawer -->
    <ListView
        android:id="@+id/navdrawer"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:drawSelectorOnTop="false">
    </ListView>
</android.support.v4.widget.DrawerLayout>

      

+3


source to share


2 answers


Tricks:

<android.support.v4.widget.DrawerLayout 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="@android:color/transparent"
tools:context="com.timesbuzz.news.MainActivity"
android:id="@+id/drawer_layout">

<FrameLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!-- you need to re-layout your widgets as you want -->
<TextView
    android:id="@+id/errorView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:text="@string/error_view_text"
    android:textSize="30sp" />

<ProgressBar
    android:id="@+id/loadingView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:indeterminate="true" />

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/contentView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- android.support.v4.view.ViewPager -->
    <fr.castorflex.android.verticalviewpager.VerticalViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>

<!-- The navigation drawer -->
<ListView
    android:id="@+id/navdrawer"
    android:layout_width="200dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:drawSelectorOnTop="false">
</ListView>

      



+3


source


Added FrameLayout as the first child of DrawerLayout. And added TextView, ProgressBar, SwipeRefreshLayout as a child of this FrameLayout and now it works as expected.



I have sorted out this question, meanwhile the same trick suggested by bharat in the comments.

+1


source







All Articles