Avoiding background to be resized when keyboard is launched in Android

If you have an ImageView and an EditText overlaying tha…

If you have an ImageView and an EditText overlaying that ImageView, in most of cases that ImageView is our background. When the EditText is tapped, keyboard will show and the ImageView will be resized.

In order to fix this, we should go to our AndroidManifest and in our activity add the line android:windowSoftInputMode=”adjustPan|stateVisible”

With this we are telling our activity’s window to not resize and make more space for our keyboard so that it wont be resizing our ImageView.

In somecases this is not enough when our Image is much bigger than our screen, and for that we should resize the image to the right size of the screen and go to our Activity’s layout. In our ImageView tag, we add the line “android:scaleType=”matrix”. With this command we are telling the compiler to scale to the image’s original matrix, which means it wont be resizing when the soft keyboard is displayed.