windowSoftInput在recycleview中隐藏项目

问题描述 投票:0回答:1

我正在创建聊天应用,到目前为止看起来像这样:

enter image description here

我开始键入的那一刻隐藏了最后两个项目,看起来像(edittext隐藏了g,h消息):

enter image description here

我的XML文件如下:

<?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>

并且我已经添加到清单android:windowSoftInputMode="adjustPan"

有没有一种方法可以确保我的回收站视图始终显示最新消息/请确保不会隐藏edittext?

谢谢

android android-layout android-recyclerview recycler-adapter
1个回答
0
投票

使用相对布局和线性布局的组合,然后在recyclerview中使用marginBottom。希望你能找到它。

<?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>

查看我上面的示例...

© www.soinside.com 2019 - 2024. All rights reserved.