android - 约束布局中的底部工作表行为
问题描述
我有一个简单的应用程序,我正在尝试添加底部工作表行为。我想保留约束布局,但我也想获得底部工作表行为。我不想要协调器布局和底页对话框。
activity_main.xml
<?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:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:enabled="false"
android:onClick="btn"
android:text="@string/btn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
layout="@layout/activity_shop"/>
</androidx.constraintlayout.widget.ConstraintLayout>
activity_shop.xml
<?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"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="@+id/shop"
android:layout_height="match_parent"
android:layout_gravity="bottom"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
app:behavior_hideable="false"
app:behavior_peekHeight="48dp">
<ImageView
android:id="@+id/arrow"
android:layout_width="match_parent"
android:padding="0dp"
android:layout_height="wrap_content"
android:contentDescription="@string/arrow"
app:srcCompat="@drawable/baseline_keyboard_arrow_up_white_48dp" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
我需要改变什么才能让这个东西工作?
解决方案
对于使用这样的使用层次结构来使用约束布局:
<CoordinatorLayout>
// *ViewGroup containing your fixed screen*
<Linear/Relative/Constraint Layout>
</Linear/Relative/Constraint Layout>
// *ViewGroup containing your bottom sheet*
<ConstraintLayout
app:behavior_hideable="false"
app:behavior_peekHeight="90dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior" >
</Constraintlayout>
</CoordinatorLayout>
推荐阅读
- javascript - Angular - 事件 OnScroll
- bash - 您将如何使用 shell 脚本安装 rpm 并将其放入 cron
- java - 如何使用正则表达式在lookhead中给出范围,例如 ^(?=(.*[az]){1,3})(?=.*[0-9]).{2,5}$
- angular - 更新到 Angular 6 版本后 Angular Cli 无法正常工作
- exception - NullPointerException 和 IllegalAccessException 的不同行为
- regex - 使用正则表达式捕获多个电话号码
- udp - 通过环回接口的 UDP 最大数据包大小
- c++ - UE4 类运算符 bool() 重载
- css - Vuejs 和 css 不能在 Firefox 上运行?
- java - 通过电子表格将 JSOUP 的 URL 导入到 Scrape