【发布时间】:2020-12-13 18:41:48
【问题描述】:
我是 Android 和 UI 开发的新手。我已经下载了最新版本的 Windows Android Studio 并做了一些基本的原生 UI,它运行良好。现在,我正在尝试开发浮动操作按钮 UI。
我在ConstraintLayout 中添加了CoordinatorLayout。 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>
【问题讨论】:
-
您在
CoordinatorLayout中缺少顶部约束。CoordinatorLayout也应该是 Root View 才能使用它。 -
尝试给协调器布局的 layout_height 和 layout_width 0dp。确保您还设置 FAB 并提供 app:layout_anchor
-
我打算添加 RecycleView 布局是顶部和底部是 FAB 页面
-
不走运。最好给我完整的更正码
-
问题与
android:src="@drawable/ic_baseline_add_24"有关,请将其更改为适当的drawable,然后它可以正常工作,或者您可以将其删除。
标签: android android-layout androidx floating-action-button