0

Im creating a chat app and so far it looks something like this:

enter image description here

The moment I start typing it hides the last 2 items and looks like (the edittext hides g,h messages):

enter image description here

My XML file looks as follows:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ChatActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_Messages"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintHeight_percent="0.9"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/ib_Send"
        style="?android:borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_location_on_black_24dp"
        app:layout_constraintHeight_percent="0.1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <EditText
        android:id="@+id/et_Message"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:hint="enter message here"
        android:backgroundTint="@color/colorLightPurple"
        android:inputType="textMultiLine|textPersonName"
        app:layout_constraintHeight_percent="0.1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/ib_Send"
        app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

and I have added to my manifest android:windowSoftInputMode="adjustPan"

Is there a way that I can make sure that my recycleview will always show the lates messages/ make sure the edittext wont hide?

Thank you

Community
  • 1
  • 1
Ben
  • 1,737
  • 2
  • 30
  • 61
  • Try putting `android:fitsSystemWindows="true"` in the root tag of your xml file. – Lalit Fauzdar Oct 12 '19 at 16:20
  • @LalitSinghFauzdar didn't work =/ – Ben Oct 12 '19 at 16:24
  • Ok, as I can see you have not connected `RecyclerView` with `EditText` using constraints, try putting `app:layout_constraintBottom_toTopOf="@+id/et_Message"` in tag of `RecyclerView` and `app:layout_constraintTop_toBottomOf="@+id/rv_Messages"` in tag of `EditText`. Supposedly, this should work. – Lalit Fauzdar Oct 12 '19 at 17:47
  • I added it, to be honest, doesn't seem like it makes any difference. I think it is more connected to the code of the adapter. like to force it show the latest – Ben Oct 12 '19 at 18:25
  • I told you to do so because the recyclerView is getting under the editText which the above mentioned constraints could stop but it didn't help it either. I think now you are left with designing a [custom layout](https://stackoverflow.com/a/35133932/8244632) using LinearLayout like everyone does. – Lalit Fauzdar Oct 13 '19 at 06:19

1 Answers1

0

Use the combination of relative and linear layout and then use marginBottom inside recyclerview. Hope you will find it.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ChatActivity">

    <include
        android:id="@+id/chat_toolbar"
        layout="@layout/app_bar_layout">
    </include>


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/private_messages_list_of_users"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/chat_toolbar"
        android:layout_above="@+id/chat_linear_layout"
        android:layout_marginBottom="6dp"
        >
    </androidx.recyclerview.widget.RecyclerView>


    <RelativeLayout
        android:id="@+id/chat_linear_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true"
        android:background="@android:color/background_light"
        android:orientation="horizontal"
        >


        <ImageButton
            android:id="@+id/send_files_btn"
            android:layout_width="60dp"
            android:layout_height="50dp"
            android:src="@drawable/ic_attach_file_black_24dp"
            android:layout_alignParentStart="true"
            android:backgroundTint="@android:color/white"
            />


        <EditText
            android:id="@+id/input_message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="type message here..."
            android:padding="15dp"
            android:maxLines="5"
            android:layout_toEndOf="@+id/send_files_btn"
            android:layout_toStartOf="@+id/send_message_btn"
            />


        <ImageButton
            android:id="@+id/send_message_btn"
            android:layout_width="60dp"
            android:layout_height="wrap_content"
            android:src="@drawable/send_message"
            android:layout_alignParentEnd="true"
            android:backgroundTint="@android:color/white"
            />

    </RelativeLayout>


</RelativeLayout>

check out my above example...

UD..
  • 80
  • 4
  • 10