首先第一件事情,我查過這個問題的答案: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是你能得到的最大影子。 –