How to make sure a particular view is displayed when the keyboard is displayed?

I have a layout with graphics at the top, EditTextin the middle and a button at some distance below it, for example:

Example layout

When a user enters text EditText, I want to copy the layout so that the Go button is still visible, even if it means cutting the image from above, for example:

Wanted layout

I know about windowSoftInputMode="adjustPan"in the manifest, but it doesn’t work, because it only pans far enough for the EditText to be visible. Is there a way to make sure it works until the button is visible too?


For comments with K_Anas, this is my layout. It has all the extra fields and gaps removed compared to the first screenshot to remove any other source of problems.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <View
        android:layout_width="300dp"
        android:layout_height="150dp"
        android:layout_alignParentTop="true"
        android:background="#999"/>

    <EditText
        android:layout_width="280dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:hint="Sample..."/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Go"/>

</RelativeLayout>
+5
3

Android, , , . , , , API, .

+2

:

android:windowSoftInputMode="adjustResize"

. docs Android.

android:windowSoftInputMode="stateVisible|adjustResize"

:

enter image description hereenter image description here

+1

I'm sure this is not the best way, but could you just change the layout attributes for your button (add / change margin) and redraw when you click edittext? Use onClickListener and possibly invalidate your button.

0
source

All Articles