2

I have a RecyclerView and an EditText inside a CardView . Purpose of the activity is to chat. So the RecyclerView contains all the messages sent and received, and the CardView is where the user types the messages. Coming to the problem, I need to move the contents up when the Keyboard pops up. Now, this doesn't seems to be a simple problem.

I tried all these Questions:

And, the solution to most comes down to altering android:windowSoftInputMode . Which I tried, switching to adjustPan and adjustResize. Here is the code to my Activity:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F0F0F0"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:paddingStart="10dp"
    android:paddingEnd="10dp"
    tools:context="com.devpost.airway.MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/chatView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </android.support.v7.widget.RecyclerView>

    <android.support.v7.widget.CardView
        android:layout_alignParentBottom="true"
        android:layout_marginTop="10dp"
        app:cardElevation="0dp"
        app:cardCornerRadius="10dp"
        android:layout_marginBottom="10dp"
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <EditText
            android:id="@+id/chat_input"
            android:paddingStart="2dp"
            android:paddingEnd="2dp"
            android:inputType="text"
            android:imeOptions="actionSend"
            android:background="@null"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v7.widget.CardView>

</RelativeLayout>

And adjustPan does work in a very vague way, I've added the screenshot below, kindly take a look :

IMAGE-1

IMAGE-1

IMAGE-2

enter image description here

Now, clearly from Image-1 and Image-2, there are few issues:

  • The ActionBar is moved up .
  • When Keyboard pops up it adds a transition animation
  • It pushes the entire RecyclerView up

So, the question is:

Is it manually possible to override any methods and implement things myself up, other than allowing the android:windowSoftInputMode to change the way it prefers? Kindly help.

Community
  • 1
  • 1
OBX
  • 5,586
  • 6
  • 25
  • 67

1 Answers1

-1
<android.support.v7.widget.RecyclerView
    android:id="@+id/chatView"
    android:layout_width="match_parent"
    android:layout_above="@+id/editorCard"
    android:layout_height="wrap_content" />

<android.support.v7.widget.CardView
    android:id="@+id/editorCard"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="10dp"
    app:cardElevation="0dp"
    app:cardCornerRadius="10dp"
    android:layout_marginBottom="10dp"
    android:layout_width="match_parent"
    android:layout_height="50dp">
 <!--your editor code-->
 </android.support.v7.widget.CardView>

wrap_content and layout_above are the key changes for the desired behavior

and in softinputmethod, make it adjustPan|adjustResize

Mohammed Atif
  • 3,892
  • 6
  • 24
  • 49