java - 软键盘:Adjust_Resize 将内容推送到屏幕外
问题描述
我正在构建一个类似应用程序的消息传递,但是我在键盘推送内容时遇到了一些问题。
我想要的是将内容向上推到与键盘高度一样多的程度,并且让我能够自由地向上滚动以查看所有以前的消息。就像大多数消息传递应用程序一样。
这是我的布局。我将布局添加到滚动视图内的布局中。
<?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:id="@+id/open_messsages_constraint"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".OpenMessages">
<ScrollView
android:id="@+id/messages_scroll2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/linearLayout">
<LinearLayout
android:id="@+id/allMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent">
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ffffff"
android:backgroundTint="#ffffff"
app:layout_constraintBottom_toBottomOf="parent">
<EditText
android:id="@+id/messageInput"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_weight="4"
android:background="@drawable/rounded_corner"
android:backgroundTint="#f1f1f1"
android:paddingLeft="20dp"
android:textColorLink="#000000" />
<com.google.android.material.button.MaterialButton
android:id="@+id/sendMessageButton"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:backgroundTint="#ffffff"
android:gravity="center"
android:stateListAnimator="@null"
app:iconTint="#000000">
</com.google.android.material.button.MaterialButton>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
将您的LinearLayout
for替换为allMessage
以下内容:
<LinearLayout
android:id="@+id/allMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_marginTop="50dp" // Add this line to view last messages
app:layout_constraintTop_toTopOf="parent">
</LinearLayout>
推荐阅读
- python - Python 3.7 中的 UML 图
- php - 不理解我在数组中遇到的错误
- c++ - 如何以函数的形式读取多个字符串输入?
- python - Pandas 合并和其他聚合技术的优化?
- css - 引导卡 - 在移动设备上查看时出现居中问题
- java - 如何强制开发人员在 SimpleDateFormat 中仅使用 'yyyy' 而不是 'YYYY'?
- azure-ad-b2c - ClaimsTransformation 似乎创建了一个额外的属性
- r - 计算当两水平因子交替时重新开始的差异
- reactjs - Dotenv-webpack 在生产中?
- java - 如何在 Jdialog 中正确关闭我的 jasperReport?