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

在android中打开软键盘时如何上移整个布局

路阳华
2023-03-14

我想移动我的布局,其中有几个视图,所以当用户触摸编辑文本,然后键盘打开,我的布局小部件上升。我甚至在清单Android:WindowsoftinPutmode=“AdjustPan”中使用了代码,然后Android:WindowsoftinPutmode=“AdjustPanAdjustStrezsize”没有任何工作,所以请帮助我
这里是我的xml

   <?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:background="@color/theme_color"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/relativeLAyoutId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:src="@drawable/osmosis_label" />

            <EditText
                android:id="@+id/login_screen_username_editText1"
                android:layout_width="220dp"
                android:layout_height="40dp"
                android:layout_below="@+id/imageView1"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="15dp"
                android:ellipsize="start"
                android:ems="10"
                android:gravity="left"
                android:hint="@string/username_editbox_text"
                android:imeOptions="actionNext"
                android:singleLine="true" >

                <requestFocus />
            </EditText>

            <EditText
                android:id="@+id/login_screen_password_editText2"
                android:layout_width="220dp"
                android:layout_height="40dp"
                android:layout_alignLeft="@+id/login_screen_username_editText1"
                android:layout_below="@+id/login_screen_username_editText1"
                android:layout_marginTop="15dp"
                android:ellipsize="start"
                android:ems="10"
                android:gravity="left"
                android:hint="@string/password_editbox_text"
                android:imeOptions="actionDone"
                android:inputType="textPassword"
                android:textColor="@color/login_layout" >
            </EditText>

            <ImageView
                android:id="@+id/login_screen_submit_button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/login_screen_password_editText2"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="15dp"
                android:src="@drawable/log_in"
                android:text="Login" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/login_screen_submit_button1"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="15dp"
                android:text="@string/registered_textview_id"
                android:textColor="@color/grey_color"
                android:textSize="18sp"
                android:textStyle="bold" />
        </RelativeLayout>

    </RelativeLayout>

共有1个答案

阎宾实
2023-03-14

把这个放到你的oncreate里。

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
 类似资料:
  • 当软键盘出现在屏幕上时,我需要软键盘和编辑文本之间正好有50dp的间隙。最终的输出会像这样 我怎样才能做到这一点?清单中的调整平移或调整调整大小并没有给我具体的差距。

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

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

  • 我有三个编辑文本字段。在这些字段中,我想只显示第一个字段的软输入键盘,并禁用后面两个字段,即日期和时间字段。 通过使用下面的代码,我可以禁用字段2和字段3的键盘,但当用户关注字段1时,键盘会出现,但当用户点击字段2或字段3时,键盘不会隐藏。虽然当第一次点击字段2或3时,不会出现键盘。 如果软输入键盘已打开,如何隐藏它?

  • 我只需要在所有其他视图内容不变的情况下使用软键盘移动编辑文本。我将我的android清单android: windowSoftInputMode字段更改为“调整无”。但它会停止将所有活动内容一起移动。我也尝试过获得软键盘高度,但无法获得可靠的方法。有什么建议吗?

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