浮动动作按钮的阴影修剪在视图边距 [英] Floating action button's shadow clipping at view margins

查看:55
本文介绍了浮动动作按钮的阴影修剪在视图边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个浮动动作按钮,固定在协调器布局的右下角.从视图的边距开始它是16dp(默认情况下包括边距,并且在dimens.xml文件中指定了边距),但是它的阴影是剪切的并且具有正方形外观(请参见下文).当我将浮动操作按钮从视图的边缘移至32dp时,其阴影会正确显示.

I have a floating action button anchored to the bottom right of a coordinator layout. It is 16dp from the margins of the view (the margins are included by default and specified in the dimens.xml file), but its shadow is clipping and has a square-shape appearance (see below). When I move the floating action button to 32dp from the margins of the view, its shadow displays properly.

我尝试设置其高程属性(android:elevation="5dp"),但这似乎没有任何效果.我还尝试将属性borderWidth设置为0(app:borderWidth="0dp"),但这也没有任何效果.

I have tried setting its elevation attribute (android:elevation="5dp"), but that seems to have no effect. I have also tried setting the attribute borderWidth to 0 (app:borderWidth="0dp") but that also had no effect.

浮动动作按钮的显示方式是否如此?

Is there a reason the floating action button is behaving like this?

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>

图片

推荐答案

问题是父母蒙蔽了阴影.查找剪切阴影的父级(不一定是层次结构中的下一个),并将其添加到xml中的视图中.

The problem is a parent clipping the shadow. Look for the parent that is clipping the shadow (is not necessarily the next in the hierarchy) and add this to the view in the xml.

android:clipChildren="false"

我一直在测试此操作,现在删除该行并将其添加到剪切视图且工作正常的父级中.

I've been testing this right now removing and adding that line to the parent that was clipping the view and is working fine.

添加其他容器或更改边距是我不建议的解决方法.太零散了.小型晶圆厂具有不同的容器尺寸,并且根据API级别(<21或> = 21)需要不同的尺寸.

Adding another containers or changing the margins is a workaround that I don't recommend. It's too patchy. The mini fabs have different container sizes and require different sizes depending on the API level (<21 or >=21).

这篇关于浮动动作按钮的阴影修剪在视图边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆