7

My application is a chat application, and its UI is:

Header of the app
List View
Chat message, input box, and send button

But the problem is when I click the edit text, the soft keyboard comes and pushes everything up, but I need the header to stay on the screen. I've attached the simplified problem images and UI code here. (I can't post multiple links or images in this post because I'm new to Stack Overflow.)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    <TextView android:text="Header contents" android:layout_width="fill_parent"
        android:textSize="20sp" android:gravity="center_horizontal"
        android:layout_height="wrap_content" />
    <ListView android:id="@android:id/list" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_weight="1" />

    <EditText android:text="" android:layout_gravity="bottom"
        android:id="@+id/EditText01" android:layout_width="fill_parent"
        android:layout_height="wrap_content"></EditText>
</LinearLayout>

Android has this requirement in the default messaging app.

Does anyone have any ideas?

hairboat
  • 650
  • 19
  • 29
Prasad De Zoysa
  • 2,488
  • 2
  • 23
  • 30

3 Answers3

4

The question is quite old, but anyhow - one way to fix this is to put everything that comes below the header within a ScrollView.

Example:

<!-- Both elements below are children of a parent RelativeLayout -->

<RelativeLayout
    android:id="@+id/custom_action_bar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:isScrollContainer="false" >

    <!-- Header goes here. -->
    <!-- This part remains fixed even with the keypad popping up. -->

</RelativeLayout>

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/custom_action_bar"
    android:isScrollContainer="true" >

    <!-- Rest of the UI -->
    <!-- This part scrolls to accommodate the keyboard -->

 </ScrollView>
Anoop
  • 1,307
  • 1
  • 14
  • 27
  • +1This is the only working solution if you have multiple views, and you need to keep few of them static on a place and let rest of the others get resized or panned. Add `android:windowSoftInputMode="adjustPan"` on the activity/application tag of manifest. – Bijay Koirala Mar 16 '15 at 10:59
1

The solution described here is the solution. Your fullscreen theme is responsible for Kamil Los not being able to reproduce your issue.

You need to adjust the activity's windowSoftInputMode tag, as described here.

Try adding the tag "android:windowSoftInputMode="adjustResize"" to the offending activity in your application's manifest.

Community
  • 1
  • 1
Weston
  • 1,882
  • 1
  • 20
  • 26
-1

That is quite strange, because I have created a new project, pasted your layout and the header does not disappear in my case (neither in 2.2 emulator nor 1.6).

Kamil Łoś
  • 218
  • 1
  • 2
  • 6
  • Ok i got the problem, but not solved yet. in my application what i have done is, i have use full screen. thats why keyboard pushing everything, see this project " http://www.freefilehosting.net/chatuilayout " – Prasad De Zoysa Jan 25 '11 at 11:18
  • Try the solution described here - http://stackoverflow.com/questions/4207880/android-how-do-i-prevent-the-soft-keyboard-from-pushing-my-view-up – Kamil Łoś Jan 25 '11 at 13:18
  • 1
    It doesn't solved my Problem. the problem is if i am in full screen mode and then key board comes and pushing everything up. – Prasad De Zoysa Jan 26 '11 at 10:25