ScrollView具有以下 struct :

    
    <androidx.constraintlayout.widget.ConstraintLayout>   
        <ScrollView>     
            <androidx.constraintlayout.widget.ConstraintLayout>
    

AlertDialog对ScrollView的使用有限制吗?

我try 在嵌套的ScrollView中编写ConstraintLayout的参数:

    
    android:scrollbars="vertical"
    android:scrollbarAlwaysDrawVerticalTrack="true"
    android:windowSoftInputMode="stateAlwaysHidden|adjustPan|adjustResize"
    android:fillViewport="true"
    

这不管用!

推荐答案

AlertDialog并不直接支持scrollView,所以你需要一个CustomDialog.

public class CustomDialog extends Dialog {

    public CustomDialog(@NonNull Context context) {
        super(context);
        init(context);
    }

    private void init(Context context) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.custom_dialog_layout);
 
        ScrollView scrollView = findViewById(R.id.scrollView);
        // Add your views or set up the ScrollView as needed
 
        getWindow().setLayout(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        );

        // Set any other properties or listeners as needed
    }
}

像下面这样实例化它

CustomDialog customDialog = new CustomDialog(context);
customDialog.show();

您的滚动视图

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <!-- Your content inside the ScrollView goes here -->

    </ScrollView>
</LinearLayout>

Java相关问答推荐

如何使用jooq generator将表名和列名映射为人类可读的?

在现代操作系统/硬件上按块访问数据值得吗?

JDK22执行repackage of goal org. springframework. boot:spring—boot—maven—plugin:3.2.3:repackage failed:unsupported class file major version 66—>

Kubernetes的Java客户端检索状态.处于终止状态的Pod的阶段';正在运行';

基于调车场算法的科学计算器

放气总是压缩整个街区吗?

我正在try 跟踪数组中最大的两个数字

如何对多个字段进行分组和排序?

在JDK 1.8源代码中,为什么使用A-B 0来确定哪个更大,而不是A B?

将PNG转换为位图自定义十六进制字符串

将关闭拍卖的TimerService

错误:未找到扩展元素在JBossEAP 7.2中安装FUSE时出错

Domino中不同的java.Protocol.handler.pkgs设置在XPages Java中导致错误

Java Flux中的延迟增加

接受类及其接口的Java类型(矛盾)

如何在Struts2中使用操作类中的结果注释重定向到不同的命名空间

无限递归Java问题

如何设置默认序列生成器分配大小

没有Google Play服务,Firebase Auth无法工作

窗口启动后不久,从java.awt.Graphics disapear创建的矩形