如何时,会出现软键盘调整布局布局、键盘

2023-09-12 10:57:02 作者:隐身守候

我想调整/重新大小的布局时,软键盘激活,如下:

I would like to adjust/re-size the layout when the soft-keyboard activated, as below:

之前和之后:

在SO找到几个资源:

How保留所有字段和文本可见的,而软键盘显示 android软键盘布局分赃时,会出现 调整布局时,软键盘是 How to keep all fields and texts visible while the soft keyboard is shown android soft keyboard spoils layout when appears Adjust layout when soft keyboard is on

不过,问题及放大器;答案是比较模糊的,这里是有什么我想更清楚的问题。

But the questions & answers are rather ambiguous, here's the question with clearer picture of what I want.

要求:

在它应该在的手机与任何屏幕尺寸。 注意到,在脸谱和保证金/填充空间订阅 Facebook的前后发生了变化。 在没有滚动视图参与。 It should work on phone with any screen sizes. Noticed that the margin/padding space at "FACEBOOK" and "Sign Up for Facebook" has changed before and after. No scroll view is involved.

推荐答案

只需添加

android:windowSoftInputMode="adjustResize"

在你的Andr​​oidManifest.xml中,你宣布这个特别的活动,这将调整布局调整选项。

in your AndroidManifest.xml where you declare this particular activity and this will adjust the layout resize option.

下面的一些源$ C ​​$ C布局设计

some source code below for layout design

<?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"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="FaceBook"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="30dp"
        android:ems="10"
        android:hint="username" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="20dp"
        android:ems="10"
        android:hint="password" />

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText2"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="18dp"
        android:layout_marginTop="20dp"
        android:text="Log In" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="17dp"
        android:gravity="center"
        android:text="Sign up for facebook"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>