FloatingActionButton 被 CoordinatorLayout 中的上一个布局覆盖
FloatingActionButton covered by prev layout in CoordinatorLayout
这是我的 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 浮动在线性布局上,但线性布局覆盖了 FAB。
我的 xml 布局截图代码:
我不知道为什么会这样。我觉得有什么地方不对?
你的 LinearLayout
比 FloatingActionButton
高,这就是为什么它躲在 LinearLayout
后面
只需从您的 LinearLayout
中删除 android:elevation="24dp"
代码
<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>
输出
这是我的 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 浮动在线性布局上,但线性布局覆盖了 FAB。
我的 xml 布局截图代码:
我不知道为什么会这样。我觉得有什么地方不对?
你的 LinearLayout
比 FloatingActionButton
高,这就是为什么它躲在 LinearLayout
只需从您的 LinearLayout
android:elevation="24dp"
代码
<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>
输出