Java – Android: using adjustpan and adjustresize doesn’t work, but I need both

I haven't formally decided whether to take this route, but there is an advertisement in my XML document. The XML document contains a relative layout containing Scrollview and advise. Advise adheres to the bottom of the relative layout, while the scroll view is elsewhere

When users focus on the EditText inside my application, some pages will be cut off. I add:

android:windowSoftInputMode="adjustPan"

But then the problem became that my adview would be cut off every time the user opened the keyboard. Therefore, to solve this problem, I changed the Android manifest to:

android:windowSoftInputMode="adjustResize"

This keeps adview at the top of the keyboard, but now adview covers some content in the application. I wonder if there is a way to keep my application content from being overwritten and keep adview above the keyboard when it appears?

I tried this, but it didn't work:

android:windowSoftInputMode="adjustPan|adjustResize"

I'm not sure if I really want to go that way. I just want to choose. In my opinion, it looks annoying

resolvent:

You cannot set adjustpan and adjustresize at the same time. They mean completely different and conflicting behaviors. They only affect the behavior of the root view when the keyboard appears or disappears

Adjustpan means "when the keyboard appears, if the view behind the keyboard gets the focus, please move the view upward so that the user can see it", but it does not allow the user to move the view himself

Adjustresize means "when the keyboard appears, change the height of the view to fit above the keyboard". This does not mean that your view will fit correctly to the space - it's your job

It sounds like what you have to do is have a Scrollview on the advertisement, which stays at the bottom of the root relativelayout view. In your case, you must want to use adjustresize to adjust the relativelayout to a shorter height. This in turn will move the advertisement to the top of the keyboard you describe. Then you must ensure that the main Scrollview is always on the advertisement, Instead of hiding behind it in some way. You may want a layout that looks 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>

Please note that Scrollview indicates the height it wants to be the parent, but it is arranged above the advertiserview. This means that it is not behind the advertiserview at the bottom edge, and you will be able to scroll to anything that exists in the Scrollview

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>