Farhan C K
Farhan C K

Reputation: 1158

Android Soft keyboard float only specific layout

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

Upvotes: 6

Views: 3845

Answers (6)

user5439728
user5439728

Reputation:

put this line in your manifest file.

 android:windowSoftInputMode="stateHidden"

Upvotes: 0

Harshad Pansuriya
Harshad Pansuriya

Reputation: 20970

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

enter image description here

KeyBoard Open Screen.

enter image description here

ImProve :

enter image description here

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

Upvotes: 3

alireza amini
alireza amini

Reputation: 1742

The fastest way is hide the layouts when soft keyboard is enable and show them again when the soft keyboard is disabled (layout2 on the xml)

Remove this Line as well

android:windowSoftInputMode="adjustPan|adjustResize"

it will work , this is just a simple way , I'm still searching for you

Upvotes: 0

Stephenraj
Stephenraj

Reputation: 755

Use different themes for both the layouts.

such as: One theme refers to adjustPan for windowSoftInputMode attribute.

and another theme refers to adjustResize for windowSoftInputMode attribute.

Upvotes: 0

Dehan Wjiesekara
Dehan Wjiesekara

Reputation: 3182

Remove the android:windowSoftInputMode="adjustPan|adjustResize"

And then Hide the layout2 programmatically when soft keyboard open. When soft keyboard close, again make the layout2 visible.

This will give user an experience exactly you want.I'm not shure there is any other way. But Keep searching. good Luck

Upvotes: -1

Smit.Satodia
Smit.Satodia

Reputation: 597

Please use this, and tell me if you find any difficulties

    <?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">
    <!--some stuff here-->
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

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

            <EditText
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="5" />

            <ImageButton
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_marginLeft="5dp"
                android:scaleType="fitStart"
                android:src="@drawable/ic_menu_send" />
        </LinearLayout>
    </ScrollView>

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

Upvotes: 0

Related Questions