首先第一件事情,我查过这个问题的答案: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它说我的高度越大,影子越大,这里有趣的是,在预览屏幕上它显示了影子,但是当在智能手机上运行时,我没有影子。
我的布局代码:
<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"/>
我尝试了一下dp,看起来在60dp时阴影开始再次消失。所以40dp或50dp是你能得到的最大影子。 –