Coldfish
Coldfish

Reputation: 378

After softkeyboard opens, the screen can't adjust itsef correctly

I read a lot of topic related to this item but none of them solved my problem. Here is the layout of my chat screen:

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/chatPage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/speech_bg" >

<include
    android:id="@+id/chatHeader"
    layout="@layout/header_chat" />

<RelativeLayout
    android:id="@+id/chatView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/chatHeader" >

    <RelativeLayout
        android:id="@+id/chatBottomView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/speech_text_bg"
        android:padding="5dp" >

        <RelativeLayout
            android:id="@+id/chatSendButton"
            android:layout_width="@dimen/chatSendButtonWidth"
            android:layout_height="@dimen/chatSendButtonHeight"
            android:layout_alignBottom="@+id/chatEditText"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="5dp"
            android:background="@drawable/chat_send_btn_selector"
            android:onClick="ChatSendButtonClick" >

            <com.xxx.Utils.MyTextView
                xmlns:customtext="http://schemas.custom.com/android/customtext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="@string/chatSendText"
                android:textColor="#ffffff"
                android:textSize="@dimen/chatSendTextSize" />
        </RelativeLayout>

        <EditText
            android:id="@+id/chatEditText"
            android:layout_width="match_parent"
            android:layout_height="@dimen/editTextHeight"
            android:layout_toLeftOf="@+id/chatSendButton"
            android:background="@drawable/edit_text"
            android:inputType="textMultiLine"
            android:maxLines="5" />
    </RelativeLayout>

    <com.handmark.pulltorefresh.library.PullToRefreshListView
        xmlns:pulltorefresh="http://schemas.custom.com/android/pulltorefresh"
        android:id="@+id/chatList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/chatBottomView"
        android:cacheColorHint="#00000000"
        android:divider="#00000000"
        android:fadingEdge="none"
        android:fadingEdgeLength="0px"
        android:listSelector="#00000000"
        pulltorefresh:type="chat" />
</RelativeLayout>

I added AdjustPan option to the AndroidManifest.xml:

<activity
    android:name=".ui.ChatActivity"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="stateHidden|adjustPan" >
</activity>

AdjustResize doesn't work in my implementation since there's not a scrollview in it, I guess.

What is the best way to resize/adjust my chat page when soft keyboard opens? As far as I see, there's no implementation for listening the keyboard in Android either. I only saw some samples related with global layoutlistener to understand the keyboard position but it didn't work well for me.

Why does adjustpan option hides my actionbar instead of only chat screen?

Upvotes: 3

Views: 1001

Answers (1)

Coldfish
Coldfish

Reputation: 378

Added to pulltorefreshlistview in chat.xml layout:

android:transcriptMode="alwaysScroll"

It solved everything. If the chat list view is scrollable in any kind of conditions, it doesn't need to listen the keyboard event to scroll the list view manually.

Hope it helps to anyone other than me either..

Upvotes: 2

Related Questions