将 CoordinatorLayout 与 SwipeRefreshLayout 以及 RecyclerView 和 FloatingActionButton 一起使用

Using CoordinatorLayout with SwipeRefreshLayout and RecyclerView and FloatingActionButton together

我试图将所有这些元素放在一起,但我看不到 FloatingActionButton 我的代码是这样的:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="xx.xx.xxxx.xxxxxxxx.Activity.MainFragment">

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/my_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:scrollbars="vertical" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="16dp"
            android:src="@drawable/ic_add_white_24dp"
            app:fab_colorNormal="@color/btn_accent"
            app:fab_colorPressed="@color/btn_accent_pressed"
            app:fab_colorRipple="@color/btn_ripple1"
            app:fab_shadow="true" />

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

我尝试切换SwipeRefreshLayout和CoordinatorLayout的位置,然后出现了FloatingActionButton,但是我无法向上滚动,因为它激活了SwipeRefreshLayout的刷新。 我怎样才能让它发挥作用?

将晶圆厂移到 SwipeRefreshLayout 之外。

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/my_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:scrollbars="vertical" />
    </android.support.v4.widget.SwipeRefreshLayout>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="16dp"
        android:src="@drawable/ic_add_white_24dp"
        app:fab_colorNormal="@color/btn_accent"
        app:fab_colorPressed="@color/btn_accent_pressed"
        app:fab_colorRipple="@color/btn_ripple1"
        app:fab_shadow="true" />
</android.support.design.widget.CoordinatorLayout>