android - EditText 居中内容的问题,如果有重力,软键盘会覆盖它
问题描述
我在 LinearLayout 中遇到 EditText 的这个问题,如果我给android:gravity="center"
或android:gravity="center_horizontal"
给 EditText,软键盘在键入时会覆盖 EditText。当我第一次触摸 edittext 时,它工作正常,但是当我开始输入 EditText 时,它在键盘后面。
如果我不提供任何重力,这个问题永远不会出现。但我希望内容居中。
这是代码
<EditText
android:id="@+id/phoneET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="@dimen/margin_bet_phn_edittxt"
android:layout_marginRight="12dp"
android:textAlignment="center"
android:gravity="center"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLength="10" />
我尝试了不同的 windowSoftInputMode 选项(android:windowSoftInputMode="adjustPan")
在清单中,但没有得到所需的结果。
还通过移除android:textAlignment="center"
或仅保留它并移除重力来尝试它。但不成功,请帮忙。
整体布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_mobile"
android:gravity="center|top"
android:orientation="vertical">
<include layout="@layout/content_header" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_top_phn_view"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:gravity="center"
android:lineSpacingExtra="6sp"
android:text="Enter phone number"
android:textColor="#ffffff"
android:textSize="@dimen/enter_phn_text_size" />
<EditText
android:id="@+id/phoneET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="@dimen/margin_bet_phn_edittxt"
android:layout_marginRight="12dp"
android:textAlignment="center"
android:gravity="center_horizontal"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLength="10" />
</LinearLayout>
解决方案
推荐阅读
- pandas - 如何在 SageMaker 笔记本终端中更新 pandas 版本?
- java - 如何删除计划作业的特定触发器
- c - C中 malloc() 函数的神秘行为
- parallel-processing - 函数式编程对并行计算有何好处?
- xslt - 将一长段重复的 XSLT 分配给变量
- asp.net-core - 从 C# 生成有效的 __RequestVerificationToken
- docker - 如果我使用绑定挂载,为什么我还需要在我的 Dockerfile 中执行 COPY?
- python - Python - 从 2 个集合中查找最接近的索引
- react-native - React native material dropdown - 如何根据下拉值呈现文本
- javascript - 如何为我的 html 表单制作验证器?