David T.
David T.

Reputation: 23371

Android how to ignore auto resizing when keyboard pops up?

let's say I have a view that is made up of 2 layers -> top layer and bottom layer. I place them both in a frame layout.

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- bottom layer -->
    <ImageView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/some_image_you_shouldnt_shrink"/>

    <!-- top layer -->
    <EditText 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/somewhat_transparent"/>

</FrameLayout>

now, presumably, when i tap on the editText, the keyboard will pop up, and shrink the size of the edit text. However, it seems that the bottom layer is ALSO getting resized. How do i prevent this bottom layer from getting resized?

Note: the framelayout is in a fragment, and the activity that holds this fragment must declare android:windowSoftInputMode="adjustResize".

EDIT*********

Just to clarify, i want the editText layer to adjust as high as the keyboard needs to. however, i don't want the image behind it to adjust at all

i only have 1 activity that handles these similar types of fragments.

Upvotes: 2

Views: 1832

Answers (2)

desidigitalnomad
desidigitalnomad

Reputation: 1443

You can't prevent a single view from resizing if you set android:windowSoftInputMode="adjustResize". But if you just want to set a non-resizing background, there is a work-around. Instead of setting the background image in the ImageView through XML, add this in your onCreate() method

getWindow().setBackgroundDrawableResource(R.drawable.some_image_you_shouldnt_shrink);

Upvotes: 1

user3291565
user3291565

Reputation:

try this in the manifest

android:windowSoftInputMode="stateVisible|adjustPan"

Upvotes: 1

Related Questions