显示键盘时向上移动 FrameLayout

问题描述 投票:0回答:1

我看到了类似的主题,但我看到的解决方案对我不起作用。

所以我有主要的 ConstraintLayout 和一些 editText。在该约束的底部,我有带有 2 个按钮的 FrameLayout。问题是,当我们单击 editText 时,键盘会出现并覆盖我的 FrameLayout,我想将该 FrameLayout 移到该键盘上方(如果显示)

框架布局代码:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent">

    <com.google.android.material.button.MaterialButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:text="Cancel" />

    <com.google.android.material.button.MaterialButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:text="Continue" />
</FrameLayout>

我尝试使用

android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="adjustPan"
但这不起作用。唯一有效的方法是添加
android:fitsSystemWindows="true"
但这也不是很好,因为添加这一行会改变我的 FrameLayout 的高度。

android android-layout user-interface keyboard android-keypad
1个回答
0
投票

最终我使用

android:fitsSystemWindows="true"

达到了我想要的目标

关键是,如果我将其添加到主布局中,它会改变它的高度并且它有自己的背景,所以我不能使用它。但我删除了 FrameLayout 的背景,在其内部添加了简单的

View
和适当的高度,并在其上添加了背景,现在它可以工作了。

© www.soinside.com 2019 - 2024. All rights reserved.