android - 如何用软键盘抬起按钮并能够滚动后面的其余内容
问题描述
我有一个Button
在屏幕底部对齐的。打开时它会Button
升起SoftKeyboard
。页面中间是空白的。但它在顶部有一些内容,在底部对齐的正上方有一些内容Button
。问题是当SoftKeyboard
打开时,中间的空白区域被底部的内容填充了。相反,我想要的是,底部内容保持在原来的位置并能够向后滚动以查看它。
解决方案
对于面临同样问题的人,我是这样解决的
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<!--data binding declaration-->
</data>
<RelativeLayout
android:id="@+id/register_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary_amber_200"
tools:context=".login.view.EnterEmailActivity">
<LinearLayout
android:id="@+id/register_ll"
android:layout_width="match_parent"
android:layout_height="92dp"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:gravity="center">
<View
android:id="@+id/register_bar"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/primary_amber_100"
android:layout_marginBottom="12dp"
android:visibility="invisible"/>
<Button
android:id="@+id/register_loginBtn"
style="@style/Button_Default_Dark_Grey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_small"
android:fitsSystemWindows="true"
android:text="@string/next"
android:layout_marginLeft="@dimen/margin_medium"
android:layout_marginRight="@dimen/margin_medium"/>
</LinearLayout>
<androidx.appcompat.widget.Toolbar
style="@style/ToolBar_Basic_Light"
android:background="@color/primary_amber_200"
android:elevation="0dp"
android:paddingLeft="@dimen/margin_medium"
android:paddingRight="@dimen/margin_medium">
<TextView
android:id="@+id/toolbar_title"
style="@style/Text_Basic_Toolbar" />
</androidx.appcompat.widget.Toolbar>
<ScrollView
android:id="@+id/register_sv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none"
android:layout_below="@id/toolbar"
android:paddingLeft="@dimen/margin_medium"
android:paddingRight="@dimen/margin_medium"
android:layout_marginBottom="@dimen/margin_xlarge92">
<RelativeLayout
android:id="@+id/register_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/register_txtHeader"
style="@style/Text_Title_H1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_large"
android:text="@string/enter_email" />
<EditText
android:id="@+id/register_email"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_below="@id/register_txtHeader"
android:layout_marginTop="@dimen/margin_xlarge"
android:background="@color/primary_amber_100"
android:gravity="center_vertical"
android:hint="@string/email"
android:inputType="textEmailAddress"
android:paddingLeft="@dimen/margin_medium"
android:paddingRight="@dimen/margin_small" />
<View
android:id="@+id/register_blank"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="@id/register_email"
/>
<RelativeLayout
android:id="@+id/register_bottom_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_small"
android:layout_below="@id/register_blank"
android:layout_marginTop="@dimen/margin_xxxlarge"
android:gravity="bottom"
android:layout_alignParentBottom="true">
<TextView
android:id="@+id/register_agreetxt"
style="@style/Text_Body_2"
android:textColor="@color/secondary_grey_800"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:text="@string/agree" />
<TextView
android:id="@+id/register_terms"
style="@style/Text_Button_Normal"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_below="@id/register_agreetxt"
android:text="@string/terms"
android:gravity="center"/>
<TextView
android:id="@+id/register_policy"
style="@style/Text_Button_Normal"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_below="@id/register_agreetxt"
android:layout_marginLeft="@dimen/margin_xlarge"
android:layout_toRightOf="@id/register_terms"
android:text="@string/policy"
android:gravity="center_vertical"/>
<TextView
android:id="@+id/register_have_accnt"
style="@style/Text_Body_2"
android:textColor="@color/secondary_grey_800"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_below="@id/register_terms"
android:text="@string/already_have_an_account"
android:gravity="center"/>
<TextView
android:id="@+id/register_login"
style="@style/Text_Button_Normal"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_below="@id/register_terms"
android:layout_marginLeft="@dimen/margin_xlarge"
android:layout_toRightOf="@id/register_have_accnt"
android:text="@string/login"
android:gravity="center"/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</layout>
不要忘记android:windowSoftInputMode="stateVisible|adjustResize"
在清单文件中添加您的活动。
推荐阅读
- php - PHP - 单击时如何将数据库中的值传递到另一个页面
- c++ - 我可以在 Qt 中使用 QUdpSockets wo 轮询或自定义类吗?
- javascript - How to fix jquery .is(':focus') not responding
- asp.net - How can I view IBM Watson Assistant conversation logs in my ASP.net application?
- javascript - 从外部的 axios 返回响应值
- java - 是否有一种方法可以在线程之间进行通信并交换信息,例如在 java 中的可运行对象中的 getter 方法
- python - 如何在不替换其他字母的情况下替换某个字母?
- php - 如何在 PHPSpreadsheet 中获取命名范围
- sql - 如果值为 NULL,则左连接,否则为内连接
- ios - “self.pushViewController”在 Swift4 中不起作用