DrawerLayout + app bar + CoordinatorLayout pull to refresh

时间:2016-04-28 09:08:51

标签: android material-design android-coordinatorlayout swiperefreshlayout

我想实现pull to refresh for full page now now mange to do in。 content_main有viewpager和recycleview。

所以我可以如何刷新整页

base.xml

 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:fitsSystemWindows="true">


<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
    android:id="@+id/navigation"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"

    android:fitsSystemWindows="true">

app_bar_main.xml

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:expandedTitleGravity="center"
                        app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">

     <android.support.v4.view.ViewPager

                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:layout_marginTop="?attr/actionBarSize"

                    app:layout_collapseMode="pin" />

            

  <include layout="@layout/content_main" />

   </android.support.design.widget.CoordinatorLayout>

1 个答案:

答案 0 :(得分:1)

看一下这段代码:

<android.support.v4.widget.DrawerLayout             
       xmlns:android="http://schemas.android.com/apk/res/android"           
       android:id="@+id/main_drawer_layout"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="@color/colorPrimaryDark"
       android:fitsSystemWindows="true">


                <android.support.design.widget.CoordinatorLayout
                    android:id="@+id/coordinator"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <include layout="@layout/app_bar_main" />

                    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
                        android:id="@+id/swipeContainer"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">


                        <include layout="@layout/content_main" />
                    </android.support.v4.widget.SwipeRefreshLayout>

                </android.support.design.widget.CoordinatorLayout>

            <android.support.design.widget.NavigationView
             android:id="@+id/navigation"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:layout_gravity="start"
             android:fitsSystemWindows="true">

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