Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use SwipeRefreshLayout inside DrawerLayout?

Both layouts are available in appcompat support library 7.

I am not getting proper result of of it.

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

That textview was visible when root layout was FrameLayout. But ever since I changed the root layout to DrawerLayout may error textview never reveals !

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>
like image 789
Rakesh Waghela Avatar asked Apr 21 '15 08:04

Rakesh Waghela


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>

like image 82
SilentKnight Avatar answered Nov 02 '22 21:11

SilentKnight


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

I sorted out this issue meanwhile same trick is suggested by bharat in comments.

like image 30
Rakesh Waghela Avatar answered Nov 02 '22 19:11

Rakesh Waghela