【问题标题】:Button under RecyclerView in BottomSheetDialogFragment is not showing properly (when STATE_COLLAPSED)BottomSheetDialogFragment 中 RecyclerView 下的按钮未正确显示(当 STATE_COLLAPSED 时)
【发布时间】:2023-02-13 14:30:21
【问题描述】:

我继承了 BottomSheetDialogFragment 的片段。 它的布局是 ConstraintLayout 并且包括:

  • 文本视图(标题)

  • RecyclerView(我的地址列表)

  • LinearLayout(图像+用于添加新地址的editText)

  • 按钮(确认选择)

    <?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/bottomSheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bottom_sheet_background"
    android:padding="14dp"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
    
    <TextView
      android:id="@+id/header"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:layout_margin="12dp"
      android:text="My addresses"
      android:textSize="24sp"
      android:textStyle="bold"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent" />
    
    <androidx.recyclerview.widget.RecyclerView
      android:id="@+id/rv"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
      app:layout_constrainedHeight="true"
      app:layout_constraintBottom_toTopOf="@id/addNewAddress"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toBottomOf="@id/header"
      tools:listitem="@layout/address_delivery_item" />
    
    <LinearLayout
      android:id="@+id/addNewAddress"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintTop_toBottomOf="@id/rv"
      app:layout_constraintBottom_toTopOf="@id/button">
    
      <ImageView
          android:id="@+id/addNewAddressButton"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:src="@drawable/ic_add_button"/>
    
      <EditText
          android:id="@+id/addNewEditText"
          android:layout_width="match_parent"
          android:layout_height="48dp"
          android:layout_weight="1"
          android:layout_gravity="center"
          android:textSize="12dp"
          android:hint="Add new address"/>
    </LinearLayout>
    
    <com.google.android.material.button.MaterialButton
      android:id="@+id/button"
      style="@style/Button.Contained"
      android:background="@drawable/app_confirm_button"
      android:text="SELECT"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>
    

我的期望是通过内容+新地址字段+按钮在两种行为状态下(STATE_COLLAPSED 和 STATE_EXPANDED)

当我以 STATE_EXPANDED 行为打开此片段时,所有显示都正确: screenshot STATE_EXPANDED behavior

当我以 STATE_COLLAPSED 行为打开此片段时,按钮和 editText 不会出现:screenshot STATE_COLLAPSED behavior

我尝试将 RecyclerView 绑定和取消绑定到 LinearLayout(id/addNewAddress) 但没有帮助。

有谁知道如何实现这种行为?使按钮出现在 STATE_COLLAPSED 中?

我将非常感谢您的帮助!

【问题讨论】:

  • 尝试将回收站视图高度设置为 android:layout_height="0dp"

标签: android-recyclerview android-constraintlayout android-bottomsheetdialog bottomsheetdialogfragment


【解决方案1】:

您找到解决方案了吗?

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-01
  • 1970-01-01
  • 2018-06-06
  • 1970-01-01
  • 2021-03-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多