java - 对话框显示 - 它不适合屏幕,我无法将对话框移动到屏幕上的其余消息
问题描述
我有一些 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();
当此警报出现时,消息太大以显示在屏幕上时,我无法将屏幕移动到消息的底部。它被阻止了。警报不会对触摸屏做出反应以向下移动到消息的其余部分。
任何想法如何解决这个问题?
解决方案
如果将布局包装在 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>
推荐阅读
- javascript - javascript 从 Date 对象获取时间信息
- sed - 添加 | 使用 sed
- dart - Dart 中的函数字段返回类型
- libraw - Libraw 不使用相机提供的白平衡
- python - python中的sql INSERT(postgres,游标,执行)
- database - 从事微软访问项目。当我尝试打开表单时收到错误“查询必须有一个目标字段”
- python - 在每个 n 位置将一个列表的值插入另一个列表
- rust - Rust 有没有办法在不生成代码的情况下执行语法和语义分析?
- java - 未正确返回 Windows 上文件路径的短名称
- angularjs - AngularJS ng-class 有两个类并缩短 ES6 if