Android:键盘与 EditText 重叠(带有打印屏幕)

2023-12-20

我有一个 EditText (用户可以输入numbers在), 因此,当用户单击 EditText 文本框时,将打开带有数字的键盘。

正如您所看到的,键盘隐藏了文本框的一小部分。

But when I press a key, for example, 0, it looks ok. This is how it looks after after clicking 0

我能做些什么(除了将 EditText 放在更高的位置之外),使它看起来像第二张图片中的那样吗?

Edit:.xml 代码:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:weightSum="1">
    <RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content">
    <LinearLayout android:layout_width="wrap_content" android:orientation="vertical" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignParentRight="true">
        <android.widget.CheckedTextView android:id="@+id/checkedTextView1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp" android:text="@string/toString"></android.widget.CheckedTextView>
        <AutoCompleteTextView android:layout_height="wrap_content" android:id="@+id/autoCompleteTextView1" android:layout_width="fill_parent" android:text="@string/emptyString" android:textSize="17sp" android:gravity="top|left" android:minHeight="62dp">
            <requestFocus></requestFocus>
        </AutoCompleteTextView>
        <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2">
            <Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.33333333333" android:text="@string/contactsString" android:textSize="17sp" android:id="@+id/contactsButton"></Button>
            <Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="@string/groupsString" android:layout_width="fill_parent" android:id="@+id/groupsButton" android:textSize="17sp"></Button>
            <Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="@string/favouritesString" android:layout_width="fill_parent" android:id="@+id/button3" android:textSize="17sp"></Button>
        </LinearLayout>
        <TextView android:id="@+id/textView1" android:text="@string/messageString" android:layout_height="wrap_content" android:textSize="17sp" android:layout_width="fill_parent"></TextView>
        <EditText android:layout_height="wrap_content" android:id="@+id/editText1" android:layout_width="fill_parent" android:gravity="top|left" android:minHeight="105dp"></EditText>
        <TextView android:id="@+id/textView2" android:text="@string/repetition" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp"></TextView>
        <Spinner android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/spinner"></Spinner>
        <LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout3" android:layout_width="fill_parent">
            <ImageView android:src="@drawable/button_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView1" android:layout_weight="0.1"></ImageView>
            <EditText android:layout_height="wrap_content" android:id="@+id/timeET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4"></EditText>
            <ImageView android:src="@drawable/button_date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView2" android:layout_weight="0.1"></ImageView>
            <EditText android:layout_height="wrap_content" android:id="@+id/dateET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4" android:layout_marginRight="3dp"></EditText>
        </LinearLayout>
        <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent">
            <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/linearLayout4" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentLeft="true">
                <Button android:layout_weight="0.5" android:layout_height="wrap_content" android:text="@string/button_ok" android:layout_width="fill_parent" android:id="@+id/button4" android:textSize="17sp"></Button>
                <Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/button5" android:layout_weight="0.5" android:text="@string/button_cancel" android:textSize="17sp"></Button>
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>

</LinearLayout>

我已经尝试过你的 XML,是的,你是对的,问题发生了。

为了解决这个问题,我在 MainActivity.java 中编写了这一行,希望对您有所帮助,并将布局 XML 放入 ScrollView 中。

Activity

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.temp);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

        final EditText time = (EditText)findViewById(R.id.timeET);
        time.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                time.requestLayout();
                MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);

                return false;
            }
        });
        final EditText date = (EditText)findViewById(R.id.dateET);
        date.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                time.requestLayout();
                MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);

                return false;
            }
        });
         }

And The XML就好像,

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

        <ScrollView android:id="@+id/scrollView1"
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent" 
        android:weightSum="1">
---
---
---
        </ScrollView> 
</LinearLayout> 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android:键盘与 EditText 重叠(带有打印屏幕) 的相关文章

随机推荐

  • C# 执行外部程序并捕获(流式传输)输出

    我正在编写一个程序来处理一些视频文件 我正在使用 ffmpeg 可执行文件将多个文件合并到一个文件中 该命令需要几分钟才能完成 因此 我需要一种方法来 监视 输出 并在 GUI 上显示进度条 查看以下 stackoverflow 主题 如何
  • 使用动态规划对列表进行分区

    我在这里发布了一些与我一直在尝试从事的项目相关的内容 但我不断遇到设计问题并且必须从头开始设计 所以我想知道我是否可以发布我正在尝试做的事情 并且有人可以帮助我了解如何获得我想要的结果 背景 我是编程新手 正在努力学习 因此 我开展了一个我
  • Binutils LD 创建巨大文件

    我正在尝试创建尽可能小的 ELF 我创建了一个像这样的测试文件 NASM 语法 SECTION text dd 0xdeadbeef 使用此链接描述文件 SECTIONS text text 然后我检查了平面二进制文件的大小 并通过两种方式
  • 将 UDF 应用于 Spark Dataframe 中的多个列

    我有一个如下所示的数据框 id age rbc bgr dm cad appet pe ane classification 3 48 0 normal 117 0 no no poor yes yes ckd 我写了一个 UDF 来转换分
  • 终止或停止 HtmlUnit

    我使用 htmlunit 测试一些网站 我注意到 Htmlunit 卡在一些网页上 这个问题导致调用 htmlunit 的线程不会终止 请您知道有什么方法可以停止 Htmlunit 就像在真正的网络浏览器中一样 您只需单击浏览器停止按钮即可
  • 考虑到每个静态库定义导出的功能(vc++ 2008),如何将多个静态链接库合并到一个 dll 中?

    鉴于每个静态库都定义导出功能 vc 2008 如何将多个静态链接库合并到单个 dll 中 在存在单个 dll 项目和静态链接的多个子项目 在 dll 项目中 的多项目布局中 尽管被标记为 declspec export 子项目 lib 中的
  • python Tkinter 中的简单加载屏幕

    我是一个Python初学者 尤其是tkinter 我想制作一个简单的 python 脚本的 加载屏幕 并在脚本结束后关闭 但制作窗户需要mainloop函数 这意味着它将无限循环或等待用户交互 或者我认为如此 并且它将消除 加载 屏幕的想法
  • Python 将 k-means 集群与实例关联

    我已阅读文档here http scikit learn org stable modules generated sklearn cluster KMeans html以及看着this http fromdatawithlove theg
  • 在 MongoDB 中搜索多个集合

    我知道 MongoDB 的理论以及不支持联接的事实 并且我应该尽可能使用嵌入文档或非规范化 但这里是 我有多个文档 例如 用户 嵌入了 Suburbs 但也有 名字 姓氏 郊区 其中嵌入州 嵌入 School 的 Child 属于 User
  • 在maven中查找定义属性的地方

    我目前正在各种项目和 git repo 中重构大量 pom xml 有时 项目 A 中的 pom 需要项目 B 中定义的工件 其版本由属性定义
  • 如何构建自动更新的拖放层次树

    我目前正在 R 工作 需要一种可视化分层树的方法 我希望能够最初定义一棵树 其中每个节点都有一个父节点 每个父节点可以有多个子节点 我希望能够将节点拖放到不同父级下并执行一些计算 在 R 中 然后在可视化上进行更新 例如假设每个节点都有一个
  • 正则表达式“包含”另一个正则表达式

    有没有办法测试一个正则表达式是否 包含 另一个正则表达式 例如 RegEX1 a b RegEx2 a1 b RegEX1 包含 RegEX2 据我所知 这是不可能的 我错了吗 OK joel neely has shown that it
  • C++ Boost.ASIO async_read_until 慢

    我遇到了一个不寻常的问题 我有一个 C Boost ASIO Web 服务器 为了处理传入请求 我使用以下代码 boost asio async read until socket response r n r n boost bind c
  • 如何使用seaborn制作气泡图

    import matplotlib pyplot as plt import numpy as np data x IEEE Elsevier Others y 7 6 2 import seaborn as sns plt legend
  • Modelica - Dymola Python 界面:将输出格式设置为文本

    我通过 Dymola Python 界面使用 Dymola 运行 Modelica 模拟 我的目标是将结果文件写入文本输出 即写入 txt文件 即使我的模型包含注释 Dymola experimentSetupOutput textual
  • C/C++ 中的单引号、双引号和 sizeof('a')

    我正在看问题C 或 C 中的单引号与双引号 https stackoverflow com questions 3683602 single quotes vs double quotes in c 我无法完全理解给出的解释 所以我写了一个
  • 位运算符优先级

    我在类 C 语言中遇到过几次的问题是 original included excluded BAD 由于优先级 它解析为 original included excluded excluded has no effect 有谁知道三个独立优
  • Git 预提交挂钩在 GitHub for mac 中失败(在命令行上运行)

    我创建了一个非常简单的预提交脚本 usr bin env sh Run tests npm test if ne 0 then echo Tests failed Aborting exit 1 fi exit 0 当我跑步时git com
  • MyBatis - 找不到构造函数

    我在 MyBatis 映射方面遇到问题 我有一个像这样的域类 public class MyClass private Long id private Date create private String content MyClass L
  • Android:键盘与 EditText 重叠(带有打印屏幕)

    我有一个 EditText 用户可以输入numbers在 因此 当用户单击 EditText 文本框时 将打开带有数字的键盘 正如您所看到的 键盘隐藏了文本框的一小部分 But when I press a key for example