5

我试图将所有这些元素放在一起,但我看不到 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 的刷新。我怎样才能让它工作?

4

1 回答 1

10

将晶圆厂移到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>
于 2015-08-19T23:36:42.823 回答