首页 > 解决方案 > 对话框显示 - 它不适合屏幕,我无法将对话框移动到屏幕上的其余消息

问题描述

我有一些 dialog_alert.xml

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorWhite">

    <LinearLayout
        android:id="@+id/cv"
        android:layout_width="match_parent"
        android:layout_gravity="center"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:elevation="4dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorAccent"
                android:gravity="center"
                android:padding="15dp"
                android:text="@{vm.title}"
                android:textColor="@color/colorWhite"
                android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
            <ProgressBar
                style="@style/ProgresBarTop"
                android:indeterminate="@{vm.working}"
                android:layout_margin="0dp"
                android:padding="0dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:padding="15dp"
                android:text="@{vm.message}"
                android:textColor="@color/colorBlack" />


        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" >
        <Button
            style="@style/ActionButton"
            android:layout_gravity="center_horizontal"
            android:text="@string/ok"
            android:onClick="@{v-> vm.okClick(v)}"/>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

并在视图模型中

AlertDialog ad = new AlertDialog(context, R.string.synchro, sb.toString()
                        , SYNC_COMPLETE_DIALOG);

ad.show();

当此警报出现时,消息太大以显示在屏幕上时,我无法将屏幕移动到消息的底部。它被阻止了。警报不会对触摸屏做出反应以向下移动到消息的其余部分。

任何想法如何解决这个问题?

标签: javaandroiddialogandroid-alertdialog

解决方案


如果将布局包装在 a 中<ScrollView>,则可以上下滚动对话框内容。例如,在您的 XML 中,使用如下内容:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- YOUR EXISTING LAYOUT CODE GOES HERE -->

</ScrollView>

推荐阅读