Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 706
Farhan C K Avatar asked Jul 09 '16 11:07

Farhan C K


1 Answers

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.

like image 168
Harshad Pansuriya Avatar answered Sep 27 '22 20:09

Harshad Pansuriya