android - Android:layout_anchor 未在 ConstraintLayout 中显示
问题描述
我想在我尝试使用的搜索图标旁边添加浮动图标加底部
app : layout_anchor="@+id/bottom_nav"
这个 layout_anchor 在我输入 xml 代码时显示,但我尝试在此之后添加 xml 代码,浮动栏也不在搜索图标之后
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav_menu" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add"
app:backgroundTint="@color/colorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/> </androidx.constraintlayout.widget.ConstraintLayout>
如果我删除这些行,它也会显示错误 this-view-is-not-constrained-it-only-has-designtime-positions-so-it-will-jump to.....
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
bottom_nav_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="@string/home_menu"
android:id="@+id/home_menu"
android:icon="@drawable/ic_home"
/>
<item android:title="@string/search_menu"
android:id="@+id/search_menu"
android:icon="@drawable/ic_search"
/>
<item android:title="@string/list_menu"
android:id="@+id/list_menu"
android:icon="@drawable/ic_filter_list"
/>
<item android:title="@string/settings_menu"
android:id="@+id/setting_menu"
android:icon="@drawable/ic_settings"
/>
</menu>
解决方案
layout_anchor
是CoordinatorLayout
not的一个属性ConstraitLayout
试试这个
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/bottom_nav_menu" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_add"
app:elevation="100dp"
app:backgroundTint="@color/colorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
或BottomAppBar
与预建工厂一起使用
推荐阅读
- python - 查找符合条件的第一个值,而不是其索引
- java - Eclipse 远程调试停止 java 监听调试端口
- javascript - 通过鼠标单击获取表格行的值?(jQuery)
- scala - Scala 功能测试:如何进行否定断言?
- python - (自动操作)Odoo 的 write() 问题并执行 for 循环
- arrays - Laravel - 检查数组中是否存在值
- java - 如何将 Java SecretKeyFactory.generateSecret() 移植到 Python?
- sql - 在连接的 ON 子句中使用 case
- java - 你如何实例化具有相互循环引用的类,而不必在 Java 中使用“NULL”?
- java - 使用 json 在 c++ 和 java 之间交换对象