【问题标题】:Using CoordinatorLayout with SwipeRefreshLayout and RecyclerView and FloatingActionButton together将 CoordinatorLayout 与 SwipeRefreshLayout 以及 RecyclerView 和 FloatingActionButton 一起使用
【发布时间】:2015-11-13 09:12:11
【问题描述】:

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

【问题讨论】:

    标签: android android-recyclerview swiperefreshlayout floating-action-button coordinator-layout


    【解决方案1】:

    将晶圆厂移出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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-02
      • 2015-08-21
      • 1970-01-01
      • 1970-01-01
      • 2020-12-07
      • 1970-01-01
      • 2014-09-30
      相关资源
      最近更新 更多