4

I haven't officially decided if I want to head this route or not but I have an adview in my XML document. The XML document contains a Relative layout that contains a ScrollView and and Adview. The Adview sticks to the bottom of the relative layout while the scrollview is everywhere else.

When a user focuses on an edittext inside of my app, some of the page would be cut off. I fixed that by adding:

android:windowSoftInputMode="adjustPan"

But then the problem became that my AdView gets cut off everytime the user has the keyboard open. So to fix that issue I changed the Android Manifest to:

android:windowSoftInputMode="adjustResize"

Which kept the AdView on top of the keyboard, but now the Adview covers some of the content on the app. I was wondering if there was a way to have my app content not be covered and keep the AdView above the keyboard when it appears?

I have tried this but it did not work:

android:windowSoftInputMode="adjustPan|adjustResize"

Not sure if I actually want to go that route, I just want the choice. It kind of looks annoying in my opinion.

1 Answers1

4

You can't set adjustPan and adjustResize at the same time. They mean completely different and conflicting behaviours. They only affect how your root view behaves when the keyboard appears or disappears.

adjustPan means "When the keyboard appears, if a view behind the keyboard gains focus, move the view up so that the user can see it" but it doesn't allow the user to move the view around themselves.

adjustResize means "When the keyboard appears, change the height of the view to fit above the keyboard". That doesn't mean that your view will adapt correctly to fit in that space - that's your job.

It sounds like what you're trying to do is have a ScrollView above the advert which is stuck to the bottom of the root RelativeLayout view. In your case, you definitely want to use adjustResize to cause the RelativeLayout to resize to a shorter height. This in turn moves the advert up to the top of the keyboard as you described. Then you have to make sure that the main ScrollView is always above the advert and not somehow tucked behind it. You probably want a layout that looks something like this:

<RelativeLayout
    android:layoutWidth="match_parent"
    android:layoutHeight="match_parent">

        <ScrollView
            android:layoutWidth="match_parent"
            android:layoutHeight="match_parent"
            android:layoutAbove="@+id/advert_view">

            <!-- Your scrolling views go here -->

        </ScrollView>

        <AdvertView
            android:id="@id/advert_view"
            android:layoutWidth="match_parent"
            android:layoutHeight="wrap_content"
            android:alignParentBottom="true" />

</RelativeLayout>

Note that the ScrollView says it wants to be the height of the parent, but laid out above the AdvertView. This will mean it isn't behind the AdvertView at the bottom edge and you'll be able to scroll to anything that exists inside the ScrollView.

SDJMcHattie
  • 1,690
  • 1
  • 15
  • 21