【问题标题】:Floating Action Button not overlapping Bottom Sheet浮动操作按钮不与底部表重叠
【发布时间】:2017-05-03 12:46:09
【问题描述】:

我的问题是我的浮动操作按钮没有与协调器布局中的底部工作表重叠。我怎么解决这个问题?底层布局是一个地图片段。

The layout looks like this

XML 如下所示:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButtonAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="-32dp"
        android:layout_gravity="end|top"
        android:src="@drawable/ic_add_white_48dp"
        app:backgroundTint="@color/colorPrimary"
        app:borderWidth="0dp"
        app:elevation="4dp"
        app:fabSize="normal"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/linear_layout_bottom_sheet">

        <!-- include bottom sheet -->
        <include layout="@layout/bottom_sheet_peek" />

        <!-- include main content -->
    <include layout="@layout/bottom_sheet_content" />

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

【问题讨论】:

  • 可能是你的底片的海拔属性高于FAB。
  • 你试过用 framelayout 代替 linearlayout 吗?
  • 我认为它永远不会适用于这种布局。 FAB 不应该是底页的一部分。
  • 框架布局并不能解决问题,我认为高程仅适用于阴影。
  • 只需将您的 FAB 移动到父布局的底部或 linear_layout_bottom_sheet 下方

标签: android android-layout


【解决方案1】:

尝试在 LinearLayout 设置正边距顶部并从 FAB 中删除负边距:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButtonAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|top"
        android:src="@drawable/ic_add_white_48dp"
        app:backgroundTint="@color/colorPrimary"
        app:borderWidth="0dp"
        app:elevation="4dp"
        app:fabSize="normal"/>

    <LinearLayout

        android:layout_marginTop="32dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/linear_layout_bottom_sheet">

        <!-- include bottom sheet -->
        <include layout="@layout/bottom_sheet_peek" />

        <!-- include main content -->
        <include layout="@layout/bottom_sheet_content" />

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

【讨论】:

  • 这也行不通,here is the image
  • 尝试将透明背景设置为CoordinatorLayout,将白色背景设置为LinearLayout
猜你喜欢
  • 1970-01-01
  • 2020-03-19
  • 2015-08-26
  • 2016-11-22
  • 2016-03-27
  • 1970-01-01
  • 2017-10-16
  • 2022-10-05
  • 1970-01-01
相关资源
最近更新 更多