【问题标题】:Layout issue when the keyboard is shown显示键盘时的布局问题
【发布时间】:2011-10-27 16:16:19
【问题描述】:

这是我隐藏软键盘时的应用 但是当显示键盘时,顶部的编辑文本框就消失了(它是向上推的)。 它看起来像这样。

我的问题是如何在显示键盘时保持两个编辑框可见?我只想减少编辑框之间的空间......但两个框都可见

到目前为止我的布局是这样的

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" android:layout_width="fill_parent"
    android:id="@+id/relativeLayout1">
    <EditText android:id="@+id/editText1" android:layout_height="wrap_content"
        android:layout_alignParentTop="true" android:layout_width="fill_parent">
        <requestFocus></requestFocus>
    </EditText>
    <EditText android:id="@+id/editText2" android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" android:layout_width="fill_parent"></EditText>
    <ImageView android:id="@+id/imageView1"
        android:layout_height="wrap_content" android:layout_below="@id/editText1"
        android:layout_above="@id/editText2" android:background="@drawable/icon"
        android:layout_width="fill_parent"></ImageView>
</RelativeLayout>

【问题讨论】:

    标签: android layout android-layout android-ui android-gui


    【解决方案1】:

    转到您的 Android 清单并将“窗口软输入模式”从用于移动整个视图的 adjustPan 更改为将为您调整视图大小的 adjustResize。

    【讨论】:

    • 在我的清单中,我放了 android:windowSoftInputMode="stateVisible|adjustResize" 并且它可以工作,但是你能给我一个简短的解释这是什么吗?可以在代码中更改吗?
    • Android 会尝试为您处理视图,以确保您输入的字段不会被键盘隐藏。有很多方法可以做到这一点。平移只是将整个视图向上移动,直到您可以看到该字段。 Resize 调整整个视图的大小以占用键盘未隐藏的空间,这正是您想要的。我知道没有办法在代码中设置它,但可能有一个地方。不过,在 xml 中设置它是标准的。
    猜你喜欢
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 1970-01-01
    • 2019-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多