Question

I'm using android:windowSoftInputMode="adjustPan" in my manifest.xml. It's doing me the job just fine but there is something retarded about it. when i focus an EditText view that's, say in the bottom half of the screen, the title bar is also scrolled with the content of the activity.

image here

all i want is to freeze/float the title bar in place when scrolling the content. just like this:

image here

and no, I don't want to use adjustResize It overlaps views on top of each other

any help is greatly appreciated, been looking for the answer for a long time.

Était-ce utile?

La solution

Found it!

Simply changing the root view in the layout xml file to a ScrollView does the job.

I don't even need to specify android:windowSoftInputMode

Of course I have to have everything else in a single layout as the child of the ScrollView

Edit

your .xml file should look like this:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    ... >
    <LinearLayout>    // could be any other layout but linear works well here
        //insert all other views of the activity here
    </LinearLayout>
</ScrollView>

Autres conseils

The answer suggested by Ace is essentially what is needed. My answer just aims to make things a little clearer.

There are two things you need to do. Firstly in the Manifest set the following on the activity. android:windowSoftInputMode="adjustResize"

Then, in the activity's layout you'll want to set a ScrollView beneath the Toolbar/Title Bar, as shown in the code below.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="?attr/actionBarSize"
        .../>

    <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ...>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                ...>
           </RelativeLayout>

    </ScrollView>
</RelativeLayout>

From what I understand, here's how it works. When you open the soft keyboard on your device, it will 'adjustResize' the layout of the activity. As the layout sits in a ScrollView, this is the part which is resized, and made smaller. Therefore the Toolbar/Titlebar will stay in place and the layout in the ScrollView will be scrollable when the keyboard is shown.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top