简体   繁体   English

软键盘:Adjust_Resize 将内容推送到屏幕外

[英]Soft keyboard: Adjust_Resize pushing content offscreen

i'm build a messaging like application, but I am having some issue with the keyboard pushing up content wrong.我正在构建一个类似应用程序的消息传递,但我在键盘错误地推送内容时遇到了一些问题。

What I want is for the content to be pushed upward exactly as much as the keyboard is tall, and for me to be able to freely scroll upward to view all the previous messages.我想要的是将内容向上推的高度与键盘的高度完全一样,并且让我能够自由向上滚动以查看所有以前的消息。 Just like most messaging apps.就像大多数消息传递应用程序一样。

Here is my layout.这是我的布局。 I add layouts to the layout inside the 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>

Here is before clicking the keyboard:这是在单击键盘之前: 在我选择键盘之前。 Here is after.这是之后。 I can scroll downward sto view the message below, but I cannot scroll upward past this picture, so I am missing a message.我可以向下滚动查看下面的消息,但我无法向上滚动经过这张图片,所以我错过了一条消息。 在我点击键盘之后。

It's Work For Me :这对我有用:

android:windowSoftInputMode="adjustResize"

And Set Padding Of Your Recyclerview Bottom Padding.并设置您的 Recyclerview 底部填充的填充。

padding:20

Replace your LinearLayout for allMessage with below:将您的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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM