首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使浮动操作按钮“浮动”

无法使浮动操作按钮“浮动”
EN

Stack Overflow用户
提问于 2016-07-22 19:57:50
回答 2查看 903关注 0票数 1

首先,我已经检查了答案:How to add shadow to the FAB provided with the android support design library?

但是,即使添加app:borderWidth="0dp"elevation="6dp",它也不起作用。我检查过这个答案:https://stackoverflow.com/a/30752754/1121139它说我的高度越大,阴影就越大,有趣的是,在预览屏幕上,它显示了阴影,但当我在智能手机上运行时,我没有得到阴影。

下面是来自智能手机的截图:

下面是android studio预览屏的截图:

我的布局代码:

代码语言:javascript
复制
<RelativeLayout 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="amaz1ngc0de.com.br.materialdesign.MainActivity">

<include android:id="@+id/app_bar" layout="@layout/toolbar_app_bar"/>

<android.support.v7.widget.RecyclerView
    android:id="@+id/rv_test_fab"
    android:layout_below="@id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

</android.support.v7.widget.RecyclerView>

<android.support.design.widget.FloatingActionButton
    android:layout_margin="16dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:src="@drawable/ic_add_white_24dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    app:elevation="140dp"
    app:borderWidth="0dp"
    app:pressedTranslationZ="12dp"
    android:clickable="true"/>

EN

回答 2

Stack Overflow用户

发布于 2016-07-22 20:03:51

尝试将布局包装在CoordinatorLayout中,并将FAB放在同一级别,而不是RelativeLayout,例如:

代码语言:javascript
复制
<!-- main_layout.xml -->
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    android:fitsSystemWindows="true"
    tools:context=".activity.MainActivity">

    <include layout="@layout/toolbar_app_bar" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_test_fab"
        android:layout_below="@id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

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

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

编辑:此小部件来自设计库,您应该将其添加到应用程序的build.gradle文件中:

代码语言:javascript
复制
compile 'com.android.support:design:24.0.0'
票数 0
EN

Stack Overflow用户

发布于 2016-07-22 20:29:29

好的,我试了一下,它的阴影与高度似乎不像你想象的那样工作。这段代码给人留下了很深的阴影:

代码语言:javascript
复制
<android.support.design.widget.FloatingActionButton
    android:id="@+id/name_add"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="15dp"
    android:src="@drawable/ic_add"
    app:elevation="20dp"/>

但是如果我将仰角设置为200,阴影就会消失。因此,阴影只在一个范围内工作。

也许你可以把它理解为一个物体,将阴影投射到一个底层物体上。高度越高,两个物体之间的距离就越大,阴影就越小。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38525875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档