【发布时间】:2019-10-15 18:03:37
【问题描述】:
我正在编写一个有聊天功能的应用程序,它看起来如下:
由于某种原因,键盘隐藏了EditText 的下部。此外,它似乎隐藏了聊天中的最后 2 条消息。
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" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintBottom_toBottomOf="parent">
<EditText
android:id="@+id/et_Message"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/et_rounded"
android:fontFamily="@font/assistant"
android:hint="Type a message"
android:textSize="12sp"
android:paddingLeft="24dp"
android:inputType="textMultiLine|textPersonName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.85"/>
<ImageButton
android:id="@+id/ib_Send"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:layout_marginHorizontal="8dp"
style="?android:borderlessButtonStyle"
android:adjustViewBounds="true"
android:src="@drawable/ic_path_2830"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintWidth_percent="0.1"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
有什么原因吗?
在我的清单中,我有:
<activity android:name=".ChatActivity" android:windowSoftInputMode="adjustPan"/>
编辑:据我观察,键盘完全打开到 EditText 内文本的底部。由于该文本位于 EditText 的中间,因此它似乎隐藏了较低的灰色部分。所以据我了解,它需要从 EditText 外部的底部开始,就像从 EditText 的外部形状开始,而不是从文本开始的地方开始。
例如从这里开始;
代替:
据我了解,我需要键盘上的“下边距”之类的东西。
只是说清楚 - 我知道AdjustResize/AdjustPan。 AdjustResize 缩小了我的 EditText 所以我试图避免它。 AdjustPan 完成了这项工作,但是它将屏幕移动到了文本的底部!文字的底部不是EditText 的底部。这就是我想要实现的目标,所以AdjustPan 不仅仅解决了问题。添加marginBottom 也不能解决问题,因为它只是让AdjustPan 移动屏幕再次移动到文本底部。我试图“愚弄”AdjustPan 或添加一些偏见。
谢谢
【问题讨论】:
-
请您尝试为顶级约束布局提供一些边距底部值,例如 16dp
-
我尝试添加:android:layout_marginBottom="16dp 但它没有工作伙伴。
-
你试过把 android:windowSoftInputMode="adjustPan" 改成 android:windowSoftInputMode="adjustResize"
-
嗨@Ben,请您与我们分享您的解决方案
标签: android xml android-layout android-softkeyboard