NestedScrollView没有出现在AlertDialog中

drsehid:

我有一个具有自定义视图AlertDialog,这是视图:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    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">

    <androidx.appcompat.widget.Toolbar
        android:background="@color/grey_1"
        android:id="@+id/edit_point_toolbar"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/edit_scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ImageView
                android:id="@+id/edit_point_close"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:src="@drawable/ic_close_red_32dp"
                android:layout_margin="4dp"
                android:clickable="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <TextView
                app:layout_constraintRight_toLeftOf="@id/edit_point_close"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:text="Edit point"
                android:textColor="@color/black"
                android:textSize="15dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.appcompat.widget.Toolbar>

    <androidx.core.widget.NestedScrollView
        android:id="@+id/edit_scrollView"
        app:layout_constraintTop_toBottomOf="@id/edit_point_toolbar"
        android:layout_width="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_height="0dp">
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp">
            <EditText
                android:id="@+id/edit_point_name"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintBottom_toTopOf="@id/save_edit_point"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:minLines="3"
                android:textDirection="rtl"
                android:background="@drawable/new_book_text_box"
                android:gravity="right|top"
                android:textAlignment="gravity"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
            <Button
                app:layout_constraintTop_toBottomOf="@id/edit_point_name"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                android:id="@+id/save_edit_point"
                android:layout_width="0dp"
                app:layout_constraintWidth_percent="0.7"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="16dp"
                android:layout_marginBottom="8dp"
                android:backgroundTint="@color/green_500"
                android:text="Confirm"
                android:textColor="#FFF" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.core.widget.NestedScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

在xml设计屏幕中,我可以正常看到工具栏和NestedScrollView的内容,但是在我的应用中,NestedScrollView没有显示,我只能看到工具栏。

这是AlertDialog代码:

 AlertDialog.Builder builder = new AlertDialog.Builder(context , R.style.Theme_Dialog);
                ViewGroup viewGroup = view.findViewById(android.R.id.content);
                View dialogView = LayoutInflater.from(view.getContext()).inflate(R.layout.edit_point_dialog , viewGroup, false);
                builder.setView(dialogView);
                AlertDialog alertDialog = builder.create();
                alertDialog.show();
                Window window = alertDialog.getWindow();
                window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

我很困惑为什么NestedScrollView内容没有显示。实际上,当我将height wrap_content设置0dp时,它会显示但滚动效果不好,并且与工具栏重叠。谁能找出我在哪里错?

Bacho Kurtanidze:

我尝试了几件事,

<androidx.core.widget.NestedScrollView
    android:id="@+id/edit_scrollView"
    app:layout_constraintTop_toBottomOf="@id/edit_point_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constrainedHeight="true"
    app:layout_constraintBottom_toBottomOf="parent">

我认为这将为您提供所需的设计,但老实说,我不太清楚为什么会这样,而0dp却没有。对我来说,最奇怪的是,当视图以常规布局放大时,0dp起作用,而在AlertDialog中放大时,则不起作用。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章