Maintain View from Resizing while use `ADJUST_RESIZE`

MahmoudMabrouk(mo3ta)
2 min readMay 12, 2021

Hello All, I was developing a feature of reply to Story(like the Instagram story) and there were two points they must be achieved:
- Image of the story not being resized while the user is typing a reply.
- EditText is upped above the keyboard.

I added my question at Stackoverflow with Images.

What Solutions?

I had done tries that can be categorized into:

  • use windowSoftInputMode = adjustNothing
  • use windowSoftInputMode = adjustResize

Use adjustNothing

Here the view is maintained and not resized and it is so like Instagram but it suffers from that EditText will not be popped up above the keyboard!!. So here we need only to show EditText above Keyboard.

IDEA 1:
I thought of calculating the height of the Keyboard when it is opened and then move EditText above it, but this failed as while using adjustNothing you will not get that height. SO NEXT CODE WILL NOT HELP US:

IDEA 2:
Place EditText to the center of the screen but this is bad UX as Screens have different dimensions and Ed will not properly above the keyboard in all cases.

Use adjustResize

Here we will face the issue of resizing ImageView(or any view).
IDEA1:
use ScrollView for ImageView and EditText to be constrained to the bottom of the screen but this failed as ImageView was resized.

Finally

The view should has a fixed size and not constrained from parent( as while keyboard is opened it will be resized)

Okay, but I have to make ImageView take full width in screen, so what?
so I added any width, height at XML then at runtime I resized it to take full screen.

It works, but Images are different in sizes so it will be filled from the top, and the rest of the screen be empty which is bad so, I have added a FramLay and add ImageView as a center to it so it will have a nice UI for different images.

Hope it helps you. See you in the next articles.

--

--