android - AndroidX 中的持久底页
问题描述
layout_behavior - android.support.design.widget.BottomSheetBehavior不工作
此视图在运行时不受垂直约束,它会跳转
我仅在 Androidx 中收到此错误。那么我该如何解决这个错误。
<?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"
android:background="#efefef"
tools:context=".MainActivity">
<include layout="@layout/content_main" />
<!-- Adding bottom sheet after main content -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical"
android:padding="10dp"
app:behavior_hideable="true"
app:behavior_peekHeight="56dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
...... child layouts..
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
由于您使用的是 androidx 库,因此您必须使用Material Components Library。
使用类 com.google.android.material.bottomsheet.BottomSheetBehavior
而不是android.support.design.widget.BottomSheetBehavior
:
<LinearLayout
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
..>
或者:
<LinearLayout
app:layout_behavior="@string/bottom_sheet_behavior"
..>
还将 更改ConstraintLayout
为 CoordinatorLayout
。
推荐阅读
- jquery - 从选择中删除重复选项(在同一页面上有多个选择)jQuery
- python - 为什么这个 string.punctuation 代码不能用于剥离标点符号?
- sql-server - 将xml写入数据库的存储过程,T-SQL
- django - Django CheckConstraint:反向 ForeignKey 查找的元素不能为空
- fork - 如何安全地 fork() 多线程进程?
- arrays - Vue v-for 嵌套数组
- c# - 如何获取文本框中输入的索引
- android - 我可以“强制”Android 模拟器始终使用相同的端口吗?
- c# - RDLC 报告以前的功能不起作用
- c# - VB.Net 泛型约束等效于 C# 其中 TValue : New()