Java 软键盘:调整大小将内容推离屏幕

Java 软键盘:调整大小将内容推离屏幕,java,android,android-studio,kotlin,Java,Android,Android Studio,Kotlin,我正在构建一个类似于消息传递的应用程序,但我遇到了一些问题,键盘将内容推到了错误的位置 我想要的是内容被向上推,就像键盘一样高,并且我能够自由地向上滚动以查看之前的所有消息。就像大多数短信应用一样 这是我的布局。我将布局添加到scrollview内部的布局中 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http:/

我正在构建一个类似于消息传递的应用程序,但我遇到了一些问题,键盘将内容推到了错误的位置

我想要的是内容被向上推,就像键盘一样高,并且我能够自由地向上滚动以查看之前的所有消息。就像大多数短信应用一样

这是我的布局。我将布局添加到scrollview内部的布局中

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

这是后面的。我可以向下滚动查看下面的消息,但我无法向上滚动此图片,因此我缺少一条消息。

这是我的工作:

android:windowSoftInputMode="adjustResize"
并设置Recyclerview底部填充的填充

padding:20

所有消息的
线性布局
替换为以下内容:

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


@PrasanthS试过了。Pan不允许任何滚动内容工作,它会将我的标题从屏幕上推下。您可以通过测量键盘高度和布局高度的差异来将marginbottom设置为您的布局谢谢,但根据上面的图片,它对我不起作用。