views:

131

answers:

2

How does Android determine whether to move the layout up when showing the softkeyboard?

Note: I am aware that the activity property android:windowSoftInputMode="adjustResize|adjustResize|adjustUnspecified" exists, as described here http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft , but in my case it doesn't seem to have any effect. This is my problem:

I have two activities, pretty much the same layout, but the first one is using a ListView that holds a list of buttons. The second activity holds a scrollview with buttons. The rest is the same, same number of buttons, same height of elements, etc.

Now, when I press the search button to open the search input bar, in my first activity, the entire layouts gets moved up. While on the second activity, the layout is not being moved up but the softkeyboard just displays on top of it. This is actually how I want it to behave. How can I achieve the same with my activity that's using the ListView?

In my manifest, initially I didn't specify any android:windowSoftInputMode attribute, but even if I do, it doesn't make any difference; I tried all three values (adjustPan, adjustResize, adjustUndefined, without any difference).

This is my layout:

1) http://pastebin.com/5zzVxjbK

2) http://pastebin.com/KFtPuHvP

Interestingly though: when I set my ListView visibility in my layout 1 (left) to View.INVISIBLE, then the layout doesn not get moved up!

alt text

A: 

I can achieve this with a RelativeLayout and setting android:windowSoftInputMode="adjustPan" like so:

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

    <include android:id="@+id/Header" layout="@layout/header"
        android:layout_width="fill_parent" android:layout_height="wrap_content" />

    <ListView android:id="@+id/android:list" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_below="@id/Header"
        android:layout_above="@+id/Footer"  />

    <include android:id="@id/Footer" layout="@layout/footer"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />
</RelativeLayout>

You may be able to achive this by setting the footer gravity (or layout_gravity) to "bottom", if you want to keep the LinearLayout, but I am not sure.

iPaulPro
I do have other activities (i.e. containing a listView that fills the screen 90%, with just a small area for a tab header) in my app where the outer layout is a linear layout, and I don't experience the effect there. I only see it in some of the activities. I believe your layout above works, but I would like to understand the logic behind it so I know how I can change the existing LinearLayout and/or what exactly causes this behaviour. I'm sure there are workarounds, but I don't want to fight the symptoms, but rather the origin itself.
Mathias Lin
Did you try the footer's gravity (layout_gravity): "bottom" with "adjustPan"?
iPaulPro
It seems that ListViews are "shifted into view" unless they are anchored to the bottom of the screen, and use adjustPan. This default behavior prevents list items from being covered by the soft keyboard.
iPaulPro
@iPaulPro: I tried to set footer's gravity as mentioned, but no difference. I don't understand why ListViews behave differently than ScrollViews, both are scroll containers, and I have the put into my layout the same way.
Mathias Lin
I'm not sure, but I know that a ListView is not "simply" a scroll container. You may have to examine the respective sources to determine the difference. Or just use a RelativeLayout :)
iPaulPro
A: 

any new about this?

carloss
no, unfortunately not. I also posted it in the Android developer group on google groups, but not resolution.
Mathias Lin
:( ,If only explain it with more examples would be good. http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
carloss