android - View 边缘处的 float 操作按钮阴影剪裁

标签 android android-layout shadow floating-action-button

我有一个 float 操作按钮锚定在协调器布局的右下角。它距离 View 的边距 16dp(默认情况下包含边距,并在 dimens.xml 文件中指定),但它的阴影是剪切的并且具有方形外观(见下文)。当我将 float 操作按钮从 View 边缘移动到 32dp 时,它的阴影会正确显示。

我已经尝试设置它的海拔属性(android:elevation="5dp"),但这似乎没有效果。我也尝试将属性borderWidth设置为0(app:borderWidth="0dp"),但这也没有效果。

float 操作按钮出现这样的行为是否有原因?

XML

<android.support.design.widget.CoordinatorLayout
    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:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/create_floating_action_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_create_white_48dp"
        app:layout_anchor="@id/coordinator_layout"
        app:layout_anchorGravity="bottom|right" />

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

图片

FAB 16dp from the margin. FAB 32dp from the margin.

最佳答案

问题是父级剪辑阴影。寻找裁剪阴影的父级(不一定是层次结构中的下一个)并将其添加到 xml 中的 View 中。

android:clipChildren="false"

我现在一直在对此进行测试,删除该行并将其添加到正在剪切 View 并且工作正常的父级。

添加另一个容器或更改边距是我不推荐的解决方法。太片面了。迷你晶圆厂具有不同的容器尺寸,并且根据 API 级别(<21 或 >=21)需要不同的尺寸。

关于android - View 边缘处的 float 操作按钮阴影剪裁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31507097/

相关文章:

css - 两个元素共享半透明(没有重叠)?

swift - 透明 SCNFloor() 上的 SceneKit 阴影

java - 我可以使用另一个应用程序 B 访问应用程序 A 的内部存储器吗?

android - RecyclerView notifyItemInserted IllegalStateException

android - 以编程方式设置 View 宽度

android - 将按钮完美居中放置在屏幕上

typescript - 在 Typescript 中覆盖或隐藏 `File`

java - 从不同线程访问 Realm 数据库对象问题(仅在某些设备上)

Android:无法获取字符串资源

android - XML 布局 - 滚动后按钮不可见