我的Android应用程序中具有以下布局,但 Activity 中的windowSoftInputMode="adjustResize"存在问题。布局在屏幕底部包含一个下一个按钮。打开键盘时,该按钮与输入字段重叠而不是折叠工具栏。

android - 打开键盘时,CoordinatorLayoutLayout AdjustResize不折叠工具栏-LMLPHP

我已经尝试过

  • android:fitsSystemWindows="true"添加到父布局
  • 在 list
  • 中设置adjustPan
  • 将约束布局和按钮包装在nestedscrollview中
  • 将coordinatorlayout封装在Relativelayout中
  • 阅读:
  • adjustResize does not work with CoordinatorLayout
  • Coordinatorlayout adjustresize not working

  • 备注:

    有趣的是,当我在第一个EditText字段中键入内容时,当文本超过默认宽度时,只有这样,它才会调整工具栏的大小并将其折叠。
    <RelativeLayout 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.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/save_button">
    
        <include layout="@layout/layout_toolbar" />
    
        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
            <TextView
                android:id="@+id/report_input_name_hint"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginEnd="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:fontFamily="@font/customfont"
                android:text="@string/report_phonenumber_name_hint"
                android:textColor="@color/light_grey"
                android:visibility="invisible"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
    
            <EditText
                android:id="@+id/report_input_name"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:background="@android:color/transparent"
                android:fontFamily="@font/customfont"
                android:hint="@string/report_phonenumber_name_hint"
                android:inputType="textPersonName"
                android:maxLength="120"
                android:textColorHint="@color/text_color_hint"
                android:textSize="@dimen/text_18sp"
                app:layout_constraintEnd_toStartOf="@+id/clear_text_button_name"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/report_input_name_hint" />
    
            <ImageView
                android:id="@+id/clear_text_button_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:contentDescription="@string/accessibility_image_description_clear_text_button"
                android:padding="@dimen/linespace_10dp"
                android:visibility="invisible"
                app:layout_constraintBottom_toBottomOf="@+id/report_input_name"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="@+id/report_input_name"
                app:srcCompat="@drawable/icn_pro_cross" />
    
            <View
                android:id="@+id/textview_underline_name"
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_marginEnd="8dp"
                android:layout_marginTop="8dp"
                android:background="@color/light_grey"
                app:layout_constraintEnd_toEndOf="@+id/clear_text_button_name"
                app:layout_constraintStart_toStartOf="@+id/report_input_name"
                app:layout_constraintTop_toBottomOf="@+id/report_input_name" />
    
            <android.support.constraint.Barrier
                android:id="@+id/barrier2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:barrierDirection="bottom"
                app:constraint_referenced_ids="report_input_name,textview_underline_name,clear_text_button_name,report_input_name_hint"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textview_underline_name" />
    
            <TextView
                android:id="@+id/report_input_number_hint"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginEnd="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:fontFamily="@font/customfont"
                android:text="@string/telefoonnummer"
                android:textColor="@color/light_grey"
                android:visibility="invisible"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/barrier2" />
    
            <ImageView
                android:id="@+id/country_flag"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:adjustViewBounds="false"
                android:contentDescription="@string/accessibility_image_description_country_flag"
                android:padding="@dimen/linespace_10dp"
                android:src="@drawable/flag_netherlands"
                app:layout_constraintBottom_toBottomOf="@+id/report_input_number"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/report_input_number" />
    
            <ImageView
                android:id="@+id/dropdown_arrow"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:rotation="90"
                android:src="@drawable/dropdown_arrow"
                app:layout_constraintBottom_toBottomOf="@+id/country_flag"
                app:layout_constraintStart_toEndOf="@+id/country_flag"
                app:layout_constraintTop_toTopOf="@+id/country_flag"
                tools:ignore="ContentDescription" />
    
            <TextView
                android:id="@+id/country_code"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="4dp"
                android:fontFamily="@font/customfont"
                android:text="@string/report_phone_dutch_country_code"
                android:textColor="@color/dark_text"
                android:textSize="@dimen/text_18sp"
                app:layout_constraintBottom_toBottomOf="@+id/report_input_number"
                app:layout_constraintStart_toEndOf="@+id/dropdown_arrow"
                app:layout_constraintTop_toTopOf="@+id/report_input_number" />
    
            <EditText
                android:id="@+id/report_input_number"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:background="@android:color/transparent"
                android:focusable="true"
                android:fontFamily="@font/customfont"
                android:hint="@string/report_phone_text_hint"
                android:inputType="number"
                android:maxLength="13"
                android:textColorHint="@color/text_color_hint"
                android:textSize="@dimen/text_18sp"
                app:layout_constraintEnd_toStartOf="@+id/clear_text_button"
                app:layout_constraintStart_toEndOf="@+id/country_code"
                app:layout_constraintTop_toBottomOf="@+id/report_input_number_hint" />
    
            <ImageView
                android:id="@+id/clear_text_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:contentDescription="@string/accessibility_image_description_clear_text_button"
                android:padding="@dimen/linespace_10dp"
                android:visibility="invisible"
                app:layout_constraintBottom_toBottomOf="@+id/report_input_number"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="@+id/report_input_number"
                app:srcCompat="@drawable/icn_pro_cross" />
    
            <View
                android:id="@+id/textview_underline_number"
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_marginEnd="8dp"
                android:layout_marginTop="8dp"
                android:background="@color/light_grey"
                app:layout_constraintEnd_toEndOf="@+id/clear_text_button"
                app:layout_constraintStart_toStartOf="@+id/country_flag"
                app:layout_constraintTop_toBottomOf="@+id/report_input_number" />
    
    
            <TextView
                android:id="@+id/error_message"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:layout_marginTop="8dp"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:textColor="@color/emergency_button_color"
                app:layout_constraintEnd_toEndOf="@+id/textview_underline_number"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="@+id/textview_underline_number"
                app:layout_constraintTop_toBottomOf="@+id/textview_underline_number" />
    
        </android.support.constraint.ConstraintLayout>
    
    </android.support.design.widget.CoordinatorLayout>
    
    <Button
        android:id="@+id/save_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:background="@drawable/report_next_button_background"
        android:enabled="false"
        android:text="@string/melden_input_volgende"
        android:textAllCaps="false"
        android:textColor="@color/inactive_text"
        android:textSize="@dimen/text_16sp"
        android:textStyle="bold" />
    

    如果没有足够的空间来显示展开的工具栏下的输入字段+按钮,则在较小的设备上需要的结果:

    android - 打开键盘时,CoordinatorLayoutLayout AdjustResize不折叠工具栏-LMLPHP

    最佳答案

    使用adjustpan。它将解决您的问题。

    07-24 09:27