Android 显示键盘时如何调整布局

Android 显示键盘时如何调整布局,android,android-recyclerview,resize,chat,android-softkeyboard,Android,Android Recyclerview,Resize,Chat,Android Softkeyboard,大家早上好,我有一个小问题,调整布局时,键盘显示 在清单中,我有adjustResize,我也尝试使用adjustPan,但我在滚动recyclerview时遇到了问题 我的布局代码是: <LinearLayout android:id="@+id/layoutGeneralHome" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/to

大家早上好,我有一个小问题,调整布局时,键盘显示

在清单中,我有adjustResize,我也尝试使用adjustPan,但我在滚动recyclerview时遇到了问题

我的布局代码是:

<LinearLayout
android:id="@+id/layoutGeneralHome"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".fragments.fragment_home">

<LinearLayout
    android:id="@+id/layoutRecycler"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.9">

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

        />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.10"
    android:orientation="horizontal">

    <LinearLayout

        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.75"
        android:orientation="vertical">

        <EditText
            android:id="@+id/edtMessage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:hint="Scrivi messaggio"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.25">

        <Button
            android:id="@+id/btnSend"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="INVIA"
            android:textSize="18sp"/>

    </LinearLayout>

</LinearLayout>
</LinearLayout>


感谢谁能帮助我这是我在应用程序中的视图,工作正常,请尝试以下操作:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:mContext="hvasoftware.com.tudiendanhngon.view.activities.CommentActivity">




    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rvComment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:visibility="gone"
        ads:layout_constraintBottom_toTopOf="@+id/viewComment"
        ads:layout_constraintTop_toBottomOf="parent" />


    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:indeterminate="true"
        android:indeterminateTint="@color/colorAccent"
        android:visibility="visible"
        ads:layout_constraintBottom_toBottomOf="parent"
        ads:layout_constraintLeft_toLeftOf="parent"
        ads:layout_constraintRight_toRightOf="parent"
        ads:layout_constraintTop_toTopOf="parent"
        tools:targetApi="lollipop" />


    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/viewComment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"

        >

        <EditText
            android:id="@+id/edtComment"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:fontFamily="sans-serif-light"
            android:inputType="textCapSentences"
            android:paddingLeft="9dp"
            android:paddingRight="50dp"
            android:textColor="@color/colorAccent"
            android:textSize="14sp"
            ads:layout_constraintBottom_toBottomOf="parent"
            ads:layout_constraintLeft_toLeftOf="parent"
            ads:layout_constraintRight_toLeftOf="@+id/ibUpComment" />

        <ImageButton
            android:id="@+id/ibUpComment"
            android:layout_width="23dp"
            android:layout_height="26dp"
            ads:layout_constraintBottom_toBottomOf="@id/edtComment"
            ads:layout_constraintRight_toRightOf="parent"
            ads:layout_constraintTop_toTopOf="@+id/edtComment" />


        <ProgressBar
            android:id="@+id/progressBarUpload"
            style="?android:attr/progressBarStyle"
            android:layout_width="26dp"
            android:layout_height="26dp"
            android:layout_centerInParent="true"
            android:layout_marginEnd="16dp"
            android:indeterminate="true"
            android:indeterminateTint="@color/colorAccent"
            android:visibility="gone"
            ads:layout_constraintBottom_toBottomOf="@id/edtComment"
            ads:layout_constraintRight_toRightOf="parent"
            ads:layout_constraintTop_toTopOf="@+id/edtComment"
            tools:targetApi="lollipop" />


    </androidx.constraintlayout.widget.ConstraintLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

您无需添加scrollview,使用相对布局可以实现所需的屏幕。 我已经添加了相关的布局和代码,如下所示

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:orientation="vertical">

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

    <LinearLayout
        android:id="@+id/llSendView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.75"
            android:orientation="vertical">

            <EditText
                android:id="@+id/edtMessage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Scrivi messaggio" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.25">

            <Button
                android:id="@+id/btnSend"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="INVIA"
                android:textSize="18sp" />
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>


在布局中使用scrollView。感谢您提供的视图示例,但我无法将其应用于我的情况。你能给我解释一下布局的逻辑和为什么它会起作用吗?是的,你读得不够。我的代码非常简单,当键盘可见时,scrollview会自动调整布局。是的,但您只有textView和editText(我想预期的结果是不同的),我只有recyclerView、editText和Button。我试着插入一个滚动视图,但结果和我预想的不一样,因为编辑文本和按钮固定在底部,我必须每次向下滚动才能看到它们。好的,我更新我的答案,这是100%的工作。关键是约束是的,我不理解你的逻辑,当用RelativeLayout找到解决方案时,但约束也可以很好。谢谢你抽出时间!我删除了LinearLlayout,但它很有魅力。非常感谢。