java - 带有 stateVisible 标志的布局中的可见键盘未调整按钮大小

标签 java android android-layout autoresize

我有一个 Activity 应该显示带有某些内容的 FrameLayout 或 LinearLayout。屏幕底部应该有一个按钮。 Button 和 Layout 都必须被包裹起来,因为 android 只允许一个 Root View 。我已经通过 AndroidManifest.xml 设置了一个“adjustResize”标志。此标志应将按钮从软键盘的底部移动到顶部。问题是我无法实现这一点(按钮隐藏在软键盘下方 - 按钮不动)。使用显示的键盘将按钮移动到正确位置的唯一方法是用 ScrollView 替换线性或框架布局。

我的问题是:它只适用于 ScrollView 的原因是什么?我已经在多个 View 中使用了这种方法,即使在不同类型的 View 组中它也始终有效。有人知道吗?

我的布局是这样的:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools">

    <RelativeLayout
        style="@style/FirebaseUI.WrapperStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <!--
            Since the TextInputLayouts change size based on whether or not an error
            is showing we use a relative layout to position them absolutely
        -->
        <android.support.design.widget.TextInputLayout
            android:id="@+id/email_layout"
            style="@style/FirebaseUI.Text.TextInputLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="16dp"
            android:transitionGroup="true"
            android:transitionName="email_field"
            app:errorTextAppearance="@style/FirebaseUI.Text.ErrorText"
            app:hintTextAppearance="@style/FirebaseUI.Text.HintText"
            tools:ignore="UnusedAttribute">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/email"
                style="@style/FirebaseUI.EditText.EmailField"/>

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

        <android.support.design.widget.TextInputLayout
            android:id="@+id/name_layout"
            style="@style/FirebaseUI.Text.TextInputLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="112dp"
            app:errorTextAppearance="@style/FirebaseUI.Text.ErrorText"
            app:hintTextAppearance="@style/FirebaseUI.Text.HintText">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/name"
                style="@style/FirebaseUI.EditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:hint="@string/name_hint"/>

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

        <android.support.design.widget.TextInputLayout
            android:id="@+id/password_layout"
            style="@style/FirebaseUI.Text.TextInputLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="224dp"
            app:errorTextAppearance="@style/FirebaseUI.Text.ErrorText"
            app:hintTextAppearance="@style/FirebaseUI.Text.HintText"
            app:passwordToggleEnabled="true">

            <android.support.design.widget.TextInputEditText
                style="@style/FirebaseUI.EditText.PasswordField"
                android:id="@+id/password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

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

        <TextView
            android:id="@+id/create_account_text"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_marginTop="336dp"
            style="@style/FirebaseUI.Text.BodyText"/>


        <Button
            style="@style/FirebaseUI.Button"
            android:layout_below="@id/create_account_text"
            android:id="@+id/button_create"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:text="@string/button_text_save"/>

    </RelativeLayout>

</FrameLayout>

谢谢

最佳答案

您要在 ID 为 create_account_text 的 TextView 中添加 336dp 的 marginTop。这在大多数设备中都很多,因此当软键盘出现时,显示的屏幕量小于其他 View 和 336dp marginTop 所需的屏幕量。

当你添加一个 ScrollView 时,当 softKeyboard 出现时, View 会滚动到底部,因此会显示按钮,但其他内容不会显示。

我不知道你的需求是什么,但是如果这个336dp只是为了在屏幕上有一个空白区域,你可以将你的RelativeLayout转换成一个LinearLayout并使用布局权重来填充空白区域,所以当键盘出现时,空白区域将被调整。

如果您需要更多帮助,请提供屏幕截图。

关于java - 带有 stateVisible 标志的布局中的可见键盘未调整按钮大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42879518/

相关文章:

java - LinkedList、HashSet 和 HashMap 之间的主要区别是什么?

java - 是否有 Java 库可以进行拖放操作

java - 如何解决创建Spring上下文时的异常?

java - 'instanceof'在JVM中是如何实现的?

java - 如何从 Paint 对象获取 RGB 值

android - 将 CardView 的高度设置为屏幕尺寸的自定义百分比

找不到 Android Facebook LoginButton 类

android - 从任何地方访问上下文?全局背景?

java - 自定义 Exoplayer 播放和暂停按钮

android - 放大图像以填充 Android 中的整个 ImageView