小编jea*_*olo的帖子

NestedScrollView 未在 AlertDialog 内扩展高度

我当前正在警报对话框内使用滚动视图,并且需要滚动视图的高度增加,直到对话框达到其最大默认高度。对我来说解释起来有点困难,所以我附上了一个插图来帮助。希望如此。

在此输入图像描述

我遇到的问题是滚动视图的高度不会增长,即使我删除它app:layout_constraintBottom_toTopOf="@id/linearLayout4",它也会增长,但底部部分将被按钮布局部分隐藏。

这是我当前的代码:

<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/filter_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/dialog_box"
android:minHeight="300dp"
android:elevation="12dp">

<TextView
    android:id="@+id/filter_header"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:text="@string/filter"
    style="@style/element_header"
    android:textColor="@color/textColorDark"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/filter_reset_btn"
    android:layout_width="wrap_content"
    android:layout_height="40dp"
    android:background="?attr/selectableItemBackgroundBorderless"
    android:text="@string/reset"
    style="@style/text_info_nBold"
    android:textSize="14sp"
    android:textColor="@color/textColorDark"
    app:layout_constraintBottom_toBottomOf="@+id/filter_header"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="@+id/filter_header" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_constraintBottom_toTopOf="@id/linearLayout4"
    app:layout_constraintTop_toBottomOf="@id/filter_header"
    app:layout_constraintVertical_bias="0.0">

    <androidx.core.widget.NestedScrollView
        android:id="@+id/filter_scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:layout_marginTop="16dp"
        android:scrollbarFadeDuration="1000">

        <!-- VIEWS INSIDE HERE -->

    </androidx.core.widget.NestedScrollView>

</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/dialog_bottombar_layout"
    android:orientation="horizontal"
    android:padding="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent">

    <Button
        android:id="@+id/dialog_secondary_button"
        style="@style/low_emphasis_btn"
        android:layout_width="0dp"
        android:layout_marginEnd="8dp"
        android:layout_weight="1"
        android:backgroundTint="@color/textColorDark"
        android:text="@string/dialog_cancel"
        android:textColor="@color/textColorDark" …
Run Code Online (Sandbox Code Playgroud)

xml android scrollview android-studio android-constraintlayout

2
推荐指数
1
解决办法
2100
查看次数