Android软键盘仅浮动特定布局 [英] Android Soft keyboard float only specific layout

查看:143
本文介绍了Android软键盘仅浮动特定布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局,下面的代码

I have a layout, code below

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--some stuff here-->

<LinearLayout
    android:id="@+id/layout1"
    android:layout_alignParentBottom="true"
    android:layout_above="@+id/layout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        />
    <ImageButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:scaleType="fitStart"
        android:layout_marginLeft="5dp"
        style="@style/Base.Widget.AppCompat.Button.Borderless"
        android:src="@drawable/ic_menu_send"/>
</LinearLayout>

<LinearLayout
    android:id="@+id/layout2"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <!--some stuff here-->
</LinearLayout>
</RelativeLayout>

在上面的代码中,当显示键盘时,我希望layout2停留在bottomlayout1go up with keyboard中.如果我添加android:windowSoftInputMode="adjustPan|adjustResize",则两个布局都停留在底部.请帮助

In the above code when keyboard is show i want layout2 to stay in the bottom and layout1 to go up with keyboard. if i add android:windowSoftInputMode="adjustPan|adjustResize" both layout stay in bottom. please help

推荐答案

您可以说这不起作用

android:windowSoftInputMode="adjustPan|adjustResize"

只需对此进行更改

android:windowSoftInputMode="stateHidden"

还有以下布局中的一件事

and one more thing in your below layout

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--some stuff here-->

<LinearLayout
    android:id="@+id/layout1"
    android:layout_alignParentBottom="true"
    android:layout_above="@+id/layout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        />
    <ImageButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:scaleType="fitStart"
        android:layout_marginLeft="5dp"
        style="@style/Base.Widget.AppCompat.Button.Borderless"
        android:src="@drawable/ic_menu_send"/>
</LinearLayout>

<LinearLayout
    android:id="@+id/layout2"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@color/colorPrimary">
    <!--some stuff here-->
</LinearLayout>
</RelativeLayout>

注意:

在将此属性android:layout_above="@+id/layout2"应用于LinearLayoutlayout1之后,请删除该属性android:layout_alignParentBottom="true",您不需要它.

Keep in Mind :

When you have applied this property android:layout_above="@+id/layout2" to layout1 of your LinearLayout then remove this property android:layout_alignParentBottom="true" you don't require it.

所以现在看起来像这样

 <LinearLayout
        android:id="@+id/layout1"
        android:layout_above="@+id/layout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

注意::我要给background colorspecific height LinearLayout 2了解您的理解.

Note : I am giving background color and specific height to LinearLayout 2 for your Understandment.

输出:

正常屏幕

键盘打开屏幕.

请参见上面我制作的图像Red Mark,该属性会导致问题,否则一切正常.

see the upper Image I make Red Mark that property create the problem otherwise every thing is work fine.

这篇关于Android软键盘仅浮动特定布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆