android - 浮动操作按钮未显示在 Android 协调器布局中
问题描述
我是 Android 和 UI 开发的新手。我已经下载了最新版本的 Windows Android Studio 并做了一些基本的原生 UI,它运行良好。现在,我正在尝试开发浮动操作按钮 UI。
我在CoordinatorLayout
里面加了ConstraintLayout
。FAB 被添加到 CoordinatorLayout 中。我的 FAB 在布局预览中不可见。
我androidx.coordinatorlayout.widget.CoordinatorLayout
在该布局中看到带有背景颜色的文本。请让我知道如何解决这个问题
实施 'com.google.android.material:material:1.2.0'
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F44336"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="MissingConstraints">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_baseline_add_24"
android:layout_gravity="bottom|end"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
尝试
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F44336"
android:layout_gravity="bottom"
tools:ignore="MissingConstraints">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="104dp"
android:layout_height="107dp"
android:layout_gravity="center"
android:foregroundGravity="center"
android:visibility="visible"
android:src="@drawable/ic_baseline_add_24"
app:backgroundTint="@color/colorPrimary" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>
推荐阅读
- go - 如何解码使用 goavro.OCFWriter 编码的 Avro 消息?
- python - 在与列表混合的嵌套字典中查找键
- python - 函数不改变数组
- html - 从R中的网页解析“表单操作”属性
- c++ - "No match for operator>" when using priority queue in C++
- javascript - 如何使 JavaScript 的 replaceAll() 将小写和大写的字符串视为小写?
- java - Android 过渡动画在低于 26 的 API 中不起作用
- python - 在 Tensorflow/Keras 中为重复元素创建掩码
- javascript - Azure Function 如何将 JSON 转换为 Excel 并将其保存到 blob 存储
- javascript - 使用多个 Reducer 和 Actions Redux 的问题