2

当我点击输入一些文本时,我的程序屏幕底部有一个LinearLayout包含a ,出现键盘并且高度缩小,所以我看不到我写的内容。EditTextEditTextEditTextEditText

键盘前

键盘后

我对此进行了搜索,发现可能与AndroidManifest.xml文件有关。所以我将此行添加到文件中:

 android:windowSoftInputMode="adjustPan"

但这在我将此代码添加到清单后EditText放置在键盘后面后无法正常工作。

将代码添加到 AndroidManifest 文件后

最后我想知道有什么办法可以防止在显示键盘时调整视图大小?

我的活动 XML 代码:

<android.support.constraint.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"
android:fitsSystemWindows="false">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">
    </android.support.design.widget.AppBarLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="10"

        app:layout_constraintTop_toTopOf="parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/msgView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="9"
            android:background="@drawable/sssaaa">
        </android.support.v7.widget.RecyclerView>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#80000000"
                android:weightSum="10">
                <EditText
                    android:id="@+id/txt_message"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginBottom="5dp"
                    android:layout_weight="8.8"
                    android:background="@drawable/rounded_corner"
                    android:hint="@string/hint"
                    android:inputType="text"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:textColor="#000000" />
                <Button
                    android:id="@+id/btn_send"
                    android:layout_width="0dp"
                    android:layout_height="40dp"
                    android:layout_gravity="center_horizontal|center_vertical"
                    android:layout_weight="1"
                    android:background="@drawable/circular_button"
                    android:textColor="#000000"
                    android:textSize="18sp" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

4

2 回答 2

1

尝试这个:

android:windowSoftInputMode="stateVisible|adjustNothing"
于 2019-05-09T13:11:03.360 回答
1

我找到了一种解决方法,因为您使用的是Constraint Layout,所以我将两个Linear LayoutRecyclerView和 发送消息字段分开。由于EditText会一直在屏幕上并且RecyclerView已经包含了一个 ScrollView 他们可能会在屏幕上竞争,RecyclerView不需要占据整个屏幕。

<android.support.constraint.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"
android:fitsSystemWindows="false">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/linearLayout">

</android.support.design.widget.AppBarLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="vertical"
    android:weightSum="0"

    app:layout_constraintBottom_toTopOf="@+id/linearLayout"
    app:layout_constraintTop_toTopOf="parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/msgView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="9">

    </android.support.v7.widget.RecyclerView>


</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:orientation="vertical"
    app:layout_constraintBottom_toBottomOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#80000000"
        android:weightSum="10">

        <EditText
            android:id="@+id/txt_message"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginBottom="5dp"
            android:layout_weight="8.8"
            android:inputType="text"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:textColor="#000000" />

        <Button
            android:id="@+id/btn_send"
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_weight="1"

            android:textColor="#000000"
            android:textSize="18sp" />

    </LinearLayout>
</LinearLayout>

在此处输入图像描述

为了测试,我删除了包含可绘制对象的行,只需将它们放回去并运行代码。

Linear Layout请注意,我将父级的高度更改EditText50dp

于 2019-05-10T10:52:19.670 回答