类似聊天的布局:EditText被SoftInputKeyboard部分隐藏

时间:2017-12-25 07:51:37

标签: android android-layout

我在AndroidManifest.xml

中设置了此属性
  

机器人:windowSoftInputMode =" adjustPan"

整个布局通过键盘向上移动,但底部EditText与键盘有关填充高度的重叠。

如何解决这个问题?

<?xml version="1.0" encoding="utf-8"?>
<merge 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">

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

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/messages_recycler_view"
        style="@style/Chat.RecyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@+id/linear_layout_message_edit" />

    <LinearLayout
        android:id="@+id/linear_layout_message_edit"
        style="@style/Chat.NewMessage.Layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:layout_marginBottom="8dp"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <ImageView
            android:id="@+id/invite_rating_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:src="@drawable/vector_drawable_ic_rate_review_black_24px"
            android:visibility="gone" />

        <EditText
            android:id="@+id/message_edit"
            style="@style/Chat.NewMessage.Text"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />

        <ImageView
            android:id="@+id/submit_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/chat_new_message_margin"
            android:src="@drawable/ic_send" />
    </LinearLayout>

</android.support.constraint.ConstraintLayout>
</merge>

the bottom EditText is overlapped by keyboard about padding height

2 个答案:

答案 0 :(得分:0)

尝试在孩子中使用RelativeLayoutandroid:layout_alignParentBottom="true"。像这样:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

    <EditText
        android:id="@+id/tvInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

答案 1 :(得分:0)

以root身份使用RelativeLayout。无需在清单中设置WindowInputMode

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_chat_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="RtlHardcoded">

<android.support.v7.widget.RecyclerView
    android:id="@+id/list_chat_messages"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/layout_chat_send_container"
    android:listSelector="@android:color/transparent"
    android:stackFromBottom="true"/>

    <RelativeLayout
        android:id="@+id/layout_chat_send_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#DFDFDF"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">
        <RelativeLayout
            android:id="@+id/con"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:gravity="center_vertical"
            android:minHeight="40dp"
            >
            <EditText
                android:id="@+id/edit_chat_message"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:gravity="center_vertical"
                android:hint="Type here"
                android:layout_toLeftOf="@+id/img_chat_send"
                android:scrollbars="vertical"
                />

            <ImageView
                android:id="@+id/img_chat_send"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:background="?attr/selectableItemBackground"
                />
        </RelativeLayout>
    </RelativeLayout>