1

I make some kind of chat application, the layout contains Toolbar, RecyclerView and panel for sending messages (as on the pictures). I try to implement the following behavior: when the keyboard opens the panel with EditText AND RecyclerView are pushed up but the Toolbar remains visible. Here it is implemented in VK application: VK application

Here is my layout and the result i get

   <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context=".activity.DialogActivity">

        <include layout="@layout/toolbar_dialog" />

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">


        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/send_message_layout"
            android:clipToPadding="false"
            android:divider="@null"
            android:paddingTop="8dp"
            android:background="#EAEFF2"
            android:paddingBottom="8dp" />

        <LinearLayout
            android:id="@+id/send_message_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:elevation="8dp"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:layout_alignParentBottom="true">
            <ImageView
                android:id="@+id/iv_image"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:alpha=".5"
                android:background="?selectableItemBackground"
                android:contentDescription="@string/app_name"
                android:padding="2dp"
                android:src="@mipmap/ic_launcher" />

            <EditText
                android:id="@+id/et_message"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:inputType="textMultiLine"
                android:maxLines="3"
                android:hint="Ваше сообщение"
                android:background="@android:color/transparent"
                />

            <Button
                android:id="@+id/btn_send"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Send" />

        </LinearLayout>
        </RelativeLayout>
    </android.support.design.widget.CoordinatorLayout>

In manifest:

android:windowSoftInputMode="adjustResize"

The result:

My app

As you can see my RecyclerView is overlaid by EditText and keyboard. I have tried adjustPan but it hides my toolbar. Can you bring me the solution to achieve such behavior as VK did.

CssHammer
  • 66
  • 7
  • 1
    try this mRecyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right,int bottom, int oldLeft, int oldTop,int oldRight, int oldBottom) { mRecyclerView.scrollToPosition(mMessages.size()-1); } }); – Anil Jun 27 '17 at 11:58
  • @anil Thanks for you answer, I will try it as soon as I can, but is this the most proper way? May be it can be achieved through layout configuration? – CssHammer Jun 27 '17 at 13:18
  • try using a single ConstraintLayout with the height of RecyclerView set to 0dp, so it'll rescale according to available height. Also maybe include code to have default scroll to start from the bottom. – CyberShark Apr 02 '20 at 14:19

0 Answers0