java - FloatingActionButton 与 RecyclerView 中的 CardView 重叠

标签 java android xml

我正在设计一个具有 CollapsingToolbarLayout 的应用程序,并且我希望 FloatingActionButton 与 RecyclerView 中的 CardView 重叠。我写了这段代码。

<?xml version="1.0" encoding="utf-8"?>

    <android.support.design.widget.CoordinatorLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginBottom="30dp"
        app:expandedTitleMarginEnd="50dp"
        app:expandedTitleMarginStart="30dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:scaleType="centerCrop"
        app:layout_collapseMode="parallax" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_collapseMode="pin"/>

    </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        app:layout_anchor="@+id/appbar"
        app:layout_anchorGravity="bottom|right|end"/> 

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>    

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

在 Android Lollipop 和 M 上工作正常,我看到 FAB 正确重叠到卡片 View ,但是当我在 Jelly Bean 4.3 上运行它时,我看到了这个:

http://i62.tinypic.com/2qu6i3n.jpg

为什么?怎么解决?

最佳答案

尝试一下:将 FloatingActionButton 放置在布局 XML 中的 RecyclerView 下方。如果这不起作用,请提高 FloatingActionButtonelevation 值,或降低 RecyclerViewCardView 的值>

关于java - FloatingActionButton 与 RecyclerView 中的 CardView 重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33252634/

相关文章:

ios - UITableView 中的问题

java - 解释拉解析器错误消息

android - 使用 GMail 发送带有 EXTRA_STREAM 的电子邮件 Intent 会崩溃

android - SharedPreferences 重启后不保存所有数据

java - PreparedStatement 返回 "You have an error in your SQL syntax"

java - 在Java中定义自定义数组类型

java - DisplayMessageActivity 后退按钮使我的 Android 应用程序崩溃

java - 构建后 Maven *.xml 资源未更新

java - 如何在一行上而不是按顺序打印数组值

java - 如何从数据库值预填充struts2中的表单