-3

I am trying to create a chat screen by using the Recycler view. Because of chat when ever user enter to the screen the list should scroll to last position.

My problem is when keyboard open the list is hiding. If we use adjust pan, entire view is going to up, I trying to scroll only the list, I want title bar remain same position when the keyboard open

Binil Surendran
  • 2,524
  • 6
  • 35
  • 58

2 Answers2

3

Add this to your code and check....It works fine for me....

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) 
    {
        if (mRecyclerAdapter != null) 
        {
            if (bottom < oldBottom) 
            {
                mRecyclerView.smoothScrollToPosition(mRecyclerAdapter.getItemCount() - 1);
            }
        }
    }
});

Add this line to when you get new message....

mRecyclerView.smoothScrollToPosition(mRecyclerAdapter.getItemCount() - 1);
Amit Jangid
  • 2,741
  • 1
  • 22
  • 28
0

No need to add android:windowSoftInputMode in the manifest. Just keep your recycler view above the bottom view. Hope this will be helpful.`

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            </RelativeLayout>
             <RelativeLayout
                android:id="@+id/rlBottom"
                android:layout_width="match_parent"
                android:layout_height="46dp"
                android:layout_gravity="bottom"
                android:layout_margin="@dimen/dimen_8"
                android:background="@drawable/shape_write_msg"
                android:elevation="@dimen/dimen_2">

                <EditText
                    android:id="@+id/etMessage"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginEnd="@dimen/dimen_12"
                    android:layout_marginStart="@dimen/dimen_12"
                    android:layout_toEndOf="@+id/ivAdd"
                    android:layout_toStartOf="@+id/ivSend"
                    android:background="@color/white"
                    android:focusable="true"
                    android:hint="@string/label_type_here"
                    android:inputType="textCapSentences"
                    android:textColor="@color/black"
                    android:textCursorDrawable="@null"
                    android:textSize="@dimen/sp_12"
                    android:visibility="visible" />


                <ImageView
                    android:id="@+id/ivSend"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"
                    android:layout_marginEnd="@dimen/dimen_4"
                    android:padding="@dimen/dimen_8"
                    android:src="@drawable/drawable_send"
                    android:visibility="visible" />
            </RelativeLayout>
        </android.support.v7.widget.CardView>
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

`

Mini Chip
  • 949
  • 10
  • 12