Home » Android » Android soft keyboard background image: how to move image and have proper size?-Exceptionshub

Android soft keyboard background image: how to move image and have proper size?-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:

Before you answer, please consider that I’ve tried all the following solutions:
How to adjust layout when soft keyboard appears
Move layouts up when soft keyboard is shown?
Software keyboard resizes background image on Android
https://www.semicolonworld.com/question/47224/how-to-adjust-layout-when-soft-keyboard-appears

In my login screen, I want to move my background image up along with the other elements. Here is the xml:

Clean state

1. The desired effect is actually more like when I use android:windowSoftInputMode="adjustPan" in my manifest’s activity. With adjustPan, the root RelativeLayout with the picture set as background gets nicely pushed upwards, just as I want, but everything below the focused element is cut, which I don’t want.

When using android:windowSoftInputMode="adjustResize":

2. -with the above xml, setting the picture directly in android:background="@drawable/loginpic", the picture will get squashed.

enter image description here

3. -when adding an ImageView, the picture moves up, but not as much as the bottom elements, which means that said elements will be higher up on the picture

enter image description here

4. -when using a ScrollView to wrap everything, putting the picture in an ImageView will result in a wierd behaviour where we’ll be able to scroll and we’ll see a huge white part between the soft keyboard and the lowest element (login button)

enter image description here

5. -the best result with a ScrollView is when setting the bitmap element as background (android:gravity="bottom" being key). When the soft keyboard is shown, the background picture is scrolled along with the bottom elements at the same height. BUT with the bitmap, the picture is zoomed to an extreme and not recognizable anymore. The screen is NOT scrollable (as desired).

Initial state with soft keyboard

In the end, I want to know how to avoid cutting elements below the focused one when using 1. (with adjustPan) OR how to centerCrop my picture in the bitmap xml using 5. Both would give me the desired effect.

How to&Answers: