带有 stateVisible 标志的布局中的可见键盘未调整按钮大小
Button in not resized with visible keyboard in layout with stateVisible flag
我有一个 activity,它应该显示带有某些内容的 FrameLayout 或 LinearLayout。屏幕底部应该有一个按钮。 Button 和 Layout 都必须被包裹起来,因为 android 只允许一个根视图。我通过 AndroidManifest.xml 设置了一个 "adjustResize" 标志。此标志应将按钮从软键盘的底部移动到顶部。问题是我无法实现这一点(按钮隐藏在软键盘下方 - 按钮不动)。使用显示的键盘将按钮移动到正确位置的唯一方法是用 ScrollView 替换线性或框架布局。
我的问题是:为什么它只适用于 ScrollView?我已经在多个视图中使用了这种方法,即使在不同类型的视图组中它也始终有效。有人知道吗?
我的布局是这样的:
<?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。这在大多数设备中都很多,所以当软键盘出现时,显示的屏幕量小于其他视图和 336dp marginTop 所需的屏幕量。
添加 ScrollView 时,当 softKeyboard 出现时,视图会滚动到底部,因此会显示按钮,但其他内容不会显示。
我不知道你的需求是什么,但是如果这个336dp只是为了在屏幕上有一个空白space,你可以将你的RelativeLayout转换成一个LinearLayout并使用布局权重来填充空白space,所以当键盘出现时,空白space会被调整。
如果您需要更多帮助,请提供屏幕截图。
我有一个 activity,它应该显示带有某些内容的 FrameLayout 或 LinearLayout。屏幕底部应该有一个按钮。 Button 和 Layout 都必须被包裹起来,因为 android 只允许一个根视图。我通过 AndroidManifest.xml 设置了一个 "adjustResize" 标志。此标志应将按钮从软键盘的底部移动到顶部。问题是我无法实现这一点(按钮隐藏在软键盘下方 - 按钮不动)。使用显示的键盘将按钮移动到正确位置的唯一方法是用 ScrollView 替换线性或框架布局。
我的问题是:为什么它只适用于 ScrollView?我已经在多个视图中使用了这种方法,即使在不同类型的视图组中它也始终有效。有人知道吗?
我的布局是这样的:
<?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。这在大多数设备中都很多,所以当软键盘出现时,显示的屏幕量小于其他视图和 336dp marginTop 所需的屏幕量。
添加 ScrollView 时,当 softKeyboard 出现时,视图会滚动到底部,因此会显示按钮,但其他内容不会显示。
我不知道你的需求是什么,但是如果这个336dp只是为了在屏幕上有一个空白space,你可以将你的RelativeLayout转换成一个LinearLayout并使用布局权重来填充空白space,所以当键盘出现时,空白space会被调整。
如果您需要更多帮助,请提供屏幕截图。