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

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

问题描述

我有一个布局,代码如下

<!--这里有些东西--><线性布局android:id="@+id/layout1"android:layout_alignParentBottom="true"android:layout_above="@+id/layout2"android:layout_width="match_parent"android:layout_height="wrap_content"机器人:方向=水平"><编辑文本android:layout_width="0dp"android:layout_height="wrap_content"机器人:layout_weight="5"/><图像按钮android:layout_width="50dp"android:layout_height="50dp"android:scaleType="fitStart"机器人:layout_marginLeft="5dp"style="@style/Base.Widget.AppCompat.Button.Borderless"android:src="@drawable/ic_menu_send"/></LinearLayout><线性布局android:id="@+id/layout2"android:layout_alignParentBottom="true"android:layout_width="match_parent"android:layout_height="wrap_content"机器人:方向=水平"><!--这里有些东西--></LinearLayout></RelativeLayout>

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

解决方案

你可以说这是行不通的

android:windowSoftInputMode="adjustPan|adjustResize"

就改这个

android:windowSoftInputMode="stateHidden"

在下面的布局中还有一件事

<!--这里有些东西--><线性布局android:id="@+id/layout1"android:layout_alignParentBottom="true"android:layout_above="@+id/layout2"android:layout_width="match_parent"android:layout_height="wrap_content"机器人:方向=水平"><编辑文本android:layout_width="0dp"android:layout_height="wrap_content"机器人:layout_weight="5"/><图像按钮android:layout_width="50dp"android:layout_height="50dp"android:scaleType="fitStart"机器人:layout_marginLeft="5dp"style="@style/Base.Widget.AppCompat.Button.Borderless"android:src="@drawable/ic_menu_send"/></LinearLayout><线性布局android:id="@+id/layout2"android:layout_alignParentBottom="true"android:layout_width="match_parent"android:layout_height="wrap_content"机器人:方向=水平"android:background="@color/colorPrimary"><!--这里有些东西--></LinearLayout></RelativeLayout>

记住:

当您将此属性 android:layout_above="@+id/layout2" 应用到 LinearLayoutlayout1 后,然后删除此属性android:layout_alignParentBottom="true" 你不需要它.

现在看起来像这样

 

<块引用>

注意:我给背景颜色特定高度LinearLayout 2 供您理解.

输出:

普通屏幕

键盘打开屏幕.

改进:

查看上图我制作了 Red Mark 该属性会导致问题,否则一切正常.

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>

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

解决方案

as you can say this is not work

android:windowSoftInputMode="adjustPan|adjustResize"

just change it this

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>

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.

So Now that look like this

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

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

Output :

Normal Screen

KeyBoard Open Screen.

ImProve :

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

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

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