java - 如何在约束布局中添加浮动按钮
问题描述
错误说
“Resource Errors 该项目包含资源错误,所以aapt没有成功,可能会导致渲染失败。先修复资源问题。”
如何在约束布局中添加浮动操作按钮
这是我的代码
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_wishlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_heart"
app:backgroundTint="@color/cardview_dark_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.972"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent />
</androidx.constraintlayout.widget.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"
tools:context=".MainActivity">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/abc_vector_test" />
</androidx.constraintlayout.widget.ConstraintLayout>
推荐阅读
- javascript - 是否可以在没有 npm start 的情况下运行 node.js 项目?
- java - 如何使用 java 11 生成 native-debug-symbols 文件?
- python - 如何在 AWS 组织/特定组织单元中存在的所有账户中使用 boto3 获取特定 AWS 账户标签
- c++ - 递归函数中 substr 的时间复杂度
- firebase - Android Flutter如何显示在ListView中搜索到的数据?错误:未为类“对象”定义运算符“[]”
- postman - 如何使用邮递员集合在另一个发布请求 URL 中使用 webhook URL?
- ansible - 如何在 Ansible Playbook 中组合远程环境变量
- c++ - GLFW 链接问题,因为它在 SharedLib (DLL) 中使用
- javascript - reactgridlayout:警告:道具类型失败:找到重复的子键“0”
- arrays - 在数组中找到最远的有效对