android - 如何在 Coordinatorlayout 中放置视图
问题描述
我需要使用Coordinatorlayout
才能让layout_behaviour
attrFAB
在滚动时隐藏。
通常我只会将我的 FAB 放在底端,但这次我实现了可扩展的 fab,我发现很难在 Coordinatorlayout 中将 4 个 FABS 放在彼此之上。
有什么想法我能做什么?我不介意以任何一种方式获得解决方案(在没有 Coordinatorlayout 的情况下处理隐藏在 API 23 下方的 webview 滚动上的晶圆厂,或者将晶圆厂正确地放在彼此之上Coordinatorlayout
)
目前这是我的ConstraintLayout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</WebView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:focusable="true" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:clickable="true"
android:focusable="true"
app:layout_constraintBottom_toTopOf="@+id/fab1"
app:layout_constraintEnd_toEndOf="@+id/fab1"
app:layout_constraintStart_toStartOf="@+id/fab1" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:clickable="true"
android:focusable="true"
app:layout_constraintBottom_toTopOf="@+id/fab2"
app:layout_constraintEnd_toEndOf="@+id/fab2"
app:layout_constraintStart_toStartOf="@+id/fab2" />
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
FAB 必须是协调器布局的直接子级
您可以使用
app:layout_anchor="@id/****"
app:layout_anchorGravity="center"
这个属性
对于您的情况,您可以更改 xml,如:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:layout_gravity="bottom|end"
android:clickable="true"
android:focusable="true" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="100dp"
android:layout_marginEnd="0dp"
app:layout_anchor="@id/fab1"
app:layout_anchorGravity="center"
android:clickable="true"
android:focusable="true" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginBottom="200dp"
android:clickable="true"
android:focusable="true"
app:layout_anchor="@id/fab2"
app:layout_anchorGravity="center"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
推荐阅读
- flutter - 如何在windows的flutter中为ios构建版本?
- java - 从 Java 文件中读取 PEM 编码的加密私钥
- flutter - Flutter:如何在禁用的 TextField 中更改边框颜色?
- laravel - Laravel docker compose nginx 404 Not Found
- sql - Oracle 按分钟而不是每天分组
- android - Android 徽标作为表情符号(符号)以文本形式复制和粘贴
- python - 尝试执行 ISR 执行时出错
- python - TypeError:float()参数必须是字符串或数字,而不是池化层输出中的“Dimension”和“NaN”
- android - 冲突的声明:var 适配器:NewsListAdapter,val 适配器:NewsListAdapter
- terraform - Terraform 应用失败并显示“无法读取 ssh 私钥:找不到密钥”