android - 显示或隐藏应用软键盘时 Android 应用冻结
问题描述
我有一个包含片段的活动。在该片段内部,ViewPager 中有 5 个片段网络。每个片段都有 30 多个输入字段,包括 EditTexts、自定义下拉菜单和日期选择器或嵌套的 ViewPagers,片段具有相同数量的输入字段。问题是; 当用户点击任何 EditText 输入数据时,软键盘变得可见,当它完全可见时,应用程序冻结大约 2 秒。当用户按下后退按钮隐藏软键盘时,键盘从屏幕上脱离,软键盘下方的屏幕区域变为白色,应用程序再次冻结相同的时间。每次都会发生这种情况。这是清单中的活动配置:
<activity
android:name=".activities.HomeActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" />
我尝试了不同的组合,android:windowSoftInputMode
但没有任何效果。尽管在具有相同清单配置且字段数量较少的其他活动中不会发生这种情况。有这么多的输入字段,对于用户来说,在文本字段中输入数据后应用程序冻结是非常烦人的。谁能建议我解决这个问题?
解决方案
我找到了解决方案。RelativeLayout
在大多数布局中,视图在内部使用如下属性相互垂直对齐android:layout_below
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--nested form view containers-->
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layout1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--nested form view containers-->
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/layout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layout2"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--nested form view containers-->
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
RelativeLayouts
我用垂直方向替换了root ,LinearLayouts
它做了这样的魔术:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--nested form view containers-->
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--nested form view containers-->
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/layout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--nested form view containers-->
</RelativeLayout>
</LinearLayout>
</LinearLayout>
我仍在寻找有关它如何影响键盘可见性状态的一些技术细节。如果我发现了什么,会在这里更新。
推荐阅读
- sql-server - 执行 PRINT 时省略的字符
- flutter - 如何创建抽屉的小部件
- mongodb - 使用 Mongo Operator 在 EKS/EFS 中部署 MongoDB
- javascript - 如果当前未启用,如何使 ESLint 支持实验性语法“jsx”?
- python - 我试图绘制这些子图,但它们根本没有出现在我的输出中,实际上,它们是阴影的
- javascript - 使用 sinon 对从基类继承的受保护函数进行存根
- mediawiki - 更新 mediawiki 时 LightnCandy 未发现错误
- python - Flask 中的双花括号在包围函数时是什么意思?
- javascript - word office-js:使用 CustomXmlParts 或自定义设置获取文档
- sql - SQL 聚合到最多 3 个日期范围