1

I'm creating android chat application.
However, when keyboard is opened, it little covers the EditText.
If I use "adjustResize" it dose not cover the EditText but it covers ListView.

Manifest:

android:windowSoftInputMode="stateAlwaysHidden|adjustPan"

Layout:

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


    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/lV_chat"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_above="@+id/linearLayout3"
        android:background="@color/gray"
        android:layout_below="@+id/toolbarChat"
        android:divider="@null"
        android:paddingRight="@dimen/space_6dp"
        android:paddingLeft="@dimen/space_6dp" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="@dimen/chat_text_input_height"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:id="@+id/linearLayout3"
        android:background="@color/white">

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:inputType="textMultiLine"
            android:ems="10"
            android:id="@+id/eT_chat"
            android:layout_weight="1"
            android:background="@color/transparency"
            android:layout_marginLeft="@dimen/space_20dp"    
            android:textCursorDrawable="@null" />

        <ImageButton
            android:layout_width="@dimen/chat_send_button_width"
            android:layout_height="match_parent"
            android:id="@+id/iB_send"
            android:background="@color/light_blue"
            android:src="@drawable/ic_send"
            android:scaleType="centerInside" />
    </LinearLayout>

</RelativeLayout>

keyboard is closed

keyboard is opened

Mitsuhiko Shimomura
  • 259
  • 1
  • 4
  • 14

2 Answers2

0

Try doing something like this

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

    <RelativeLayout
        android:id="@+id/mainLayout"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="50dp"
        android:fitsSystemWindows="true">


        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/lV_chat"
            android:divider="@null"
             />



    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            >

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:inputType="textMultiLine"
            android:ems="10"
            android:id="@+id/eT_chat"
            android:layout_weight="1"
            android:textCursorDrawable="@null" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/iB_send"
            android:src="@mipmap/ic_launcher"
            android:scaleType="centerInside" />
    </LinearLayout>

</RelativeLayout>
    </RelativeLayout>

you can have android:layout_marginBottom="your edittext's layout's width" to your main layout which contains listview and then it should fix your issue using Relative layout and inside that Linear layout.

and remember dont add these lines to your linear layout

android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"

Relative layout should have android:layout_alignParentBottom="true" which contains EditText and send icon.

Shishram
  • 1,514
  • 11
  • 20
0

In my opinion "adjustResize" is your best bet .This will resize the list view to accommodate the keyboard. You can use bottomPadding in the list. "adjustPan" will not be of much help as it will shift the entire layout and it will not look good.

Ajit Pratap Singh
  • 1,299
  • 12
  • 24