当前位置: 首页 > 知识库问答 >
问题:

android软键盘出现时会破坏布局

卓新知
2023-03-14

这是一个布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1" />

        <FrameLayout
            android:background="#0000ff"
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1" />

    </LinearLayout>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

我希望在触摸EditText并显示软键盘时,蓝色条保持不变。一、 我希望它的大小和位置得到保留。我在AndroidManifest中尝试了我的活动参数android:WindowsofInputMode的所有四个可能值。我的蓝条总是在软键盘上移动或收缩:

android:WindowsofInputMode=“adjustUnspecified”或默认设置:

android:windowSoftInputMode=“adjustPan”或android:windowSoftInputMode=“adjustNothing”:

android:WindowsofInputMode=“调整大小”:

当软键出现时,是否有可能保持它的大小和位置不变?

共有3个答案

长孙知
2023-03-14

我认为这是因为您正在使用的LinearLayout。您可以用相对布局更改您的内部布局吗?在您目前的情况下,键盘只是因为线性布局而更改组件之间的边距。并使用调整什么都不更改您的配置

轩辕佑运
2023-03-14

由于输入进入您的编辑文本,它总是会移动某些内容。

考虑有两种布局,一种用于键盘关闭时,另一种用于键盘打开时。

使用ViewSwitcher可能会有所帮助。

东门航
2023-03-14

您必须使用<代码>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent">
   ....
</ScrollView>

或者在AndroidManiFest中使用此代码。xml:

<activity
     android:windowSoftInputMode="adjustNothing">
</activity>
 类似资料:
  • 当软键盘出现在屏幕上时,我需要软键盘和编辑文本之间正好有50dp的间隙。最终的输出会像这样 我怎样才能做到这一点?清单中的调整平移或调整调整大小并没有给我具体的差距。

  • 我想在软键盘激活时调整版面的大小,如下所示: 前后: 在SO: 在显示软键盘时如何保持所有字段和文本可见 安卓软键盘出现时破坏布局 软键盘打开时调整布局 但问题和答案是相当模糊的,这里的问题更清楚地描述了我想要什么。 要求: 它应适用于任何屏幕大小的电话。 注意到“facebook”和“注册facebook”处的边距/填充空间前后发生了变化。 不涉及滚动视图。

  • 我想在激活软键盘时更改布局元素,如下所示: 这是一个关于我想要什么的问题。 要求: 注意到“忘记密码”视图消失,“Facebook图像”和“创建新Facebook帐户”视图完全改变。我们如何实现这样的布局。 不涉及滚动视图。 布局应该适用于任何屏幕尺寸的手机。

  • 问题内容: 打开虚拟键盘后,它将调整我的布局大小。我如何才能将键盘放在布局上?并没有改变我的布局尺寸? 问题答案: 您可以使用清单标志来配置虚拟键盘的效果。请参阅http://developer.android.com/guide/topics/manifest/activity- element.html#wsoft

  • 我的目标是实现大多数消息传递应用程序(如Facebook Messenger、Viber、What's up)在显示附件表时所做的事情。如果软键盘可见并且用户想要附加某些东西,则键盘是隐藏的,附件表会在其位置呈现。 为了实现这一点,应该在根视图大小更改时更改布局。否则,在显示/隐藏键盘之前不久应用布局更改时,就会出现图形故障。 如果我可以在键盘隐藏的确切时刻更改我的布局,我可以把它做好。我尝试过使