android – How to move up the whole layout when keyboard shown?-ThrowExceptions

Exception or error:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_gravity="bottom"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content" /> 
        </LinearLayout>    

</FrameLayout>  

in manifest:

 android:windowSoftInputMode="adjustPan"

Initial behavior:

enter image description here

Current behavior:

enter image description here

Desired behavior:

enter image description here

How to achive desired behavior of layout? adjustResize unsuitable because this option resizes layout.

Thank you for answers!

How to solve:

You probably want to take a look at this answer. A suggestion from it:

Set Window SoftInput Mode property to adjustPan and adjustResize

<activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>

###

The only way to obtain that result is resize layout.
Use android:windowSoftInputMode=”adjustResize”

###

try this one in your manifest:

android:windowSoftInputMode="adjustResize|stateUnchanged"

###

the check if the layout that contain EditText and Button is RelativeLayout.

###

Try to change FrameLayout to RelativeLayout with alignParentBottom="true" property in your LinearLayout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_alignParentBottom="true"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content" /> 
        </LinearLayout>    

</RelativeLayout>  

###

You won’t be able to implement that with adjustPan, because from the official guide

The activity’s main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

Your Button is below your current focus EditText

###

by removing below line from activity and android:windowSoftInputMode from manifest, I got whole layout scrolling which was previously hiding by

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

please check this output video link:
https://mega.nz/#!TpRCWZjY!TqDzv0Yn3Q24PR1JAdH8kRVeDf2iSa1LQbNBgF0SVHk

###

I don’t believe there is a simple way to do this. At least not as simple as setting a flag.
I had a similar situation of wanting the keyboard to rise to the level of Views well below the selected EditText. I ended up using this answer:
How to check visibility of software keyboard in Android?

and manually adjusting my View sizes when the keyboard becomes visible.

###

Just use this property in activity

android:windowSoftInputMode="adjustPan"

Leave a Reply

Your email address will not be published. Required fields are marked *