这是我的xml代码。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#0000FF"
android:id="@+id/dialog_frame"
android:orientation="vertical"
android:elevation="24dp">
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/dialog_frame"
android:id="@+id/login_close"
app:layout_anchorGravity="bottom|center_horizontal"
android:clickable="true"/>
</android.support.design.widget.CoordinatorLayout>
我希望FAB浮动在linearlayout上,但linearlayout覆盖FAB。
我的xml代码布局截图:
我不知道为什么会这样。我觉得有些不对劲?
答案 0 :(得分:3)
您的LinearLayout
海拔高于FloatingActionButton
,这就是它隐藏在LinearLayout
背后的原因
只需从android:elevation="24dp"
LinearLayout
即可
<强> CODE 强>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/dialog_frame"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#0000FF"
android:orientation="vertical">
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/login_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:layout_anchor="@id/dialog_frame"
app:layout_anchorGravity="bottom|center_horizontal" />
</android.support.design.widget.CoordinatorLayout>
<强>输出强>