[英]android - ScrollView doesn't scroll when keyboard is up
I have the following xml file in Android Studio: 我在Android Studio中有以下xml文件:
activity_register.xml activity_register.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="mk.klikniobrok.klikniobrok.RegisterActivity">
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="48dp">
<RelativeLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_top_margin"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<LinearLayout
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name_hint"
android:inputType="text"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:textSize="@dimen/input_text_size" />
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/user_hint"
android:inputType="text"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:textSize="@dimen/input_text_size" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/pass_hint"
android:inputType="textPassword"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:textSize="@dimen/input_text_size" />
<EditText
android:id="@+id/repeatPwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/repeatPwd_hint"
android:inputType="textPassword"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:textSize="@dimen/input_text_size" />
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email_hint"
android:inputType="textEmailAddress"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:textSize="@dimen/input_text_size" />
<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/phone_hint"
android:inputType="phone"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:textSize="@dimen/input_text_size" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
android:gravity="end"
android:orientation="horizontal"
android:paddingBottom="2dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="2dp">
<Button
android:id="@+id/registerButton"
style="@style/RobotoBoldButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/ripple_transparent"
android:text="РЕГИСТРИРАЈ СЕ"
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>
When the keyboard is not up I can see every element but whenever the keyboard comes up the ScrollView does not scroll down to reveal the covered elements. 当键盘没有抬起时,我可以看到每个元素,但是每当键盘抬起时,ScrollView不会向下滚动以显示覆盖的元素。 I have read through StackOverflow and added android:windowSoftInputMode="stateHidden|adjustResize" to the AndroidManifest.xml but it still does not work.
我已阅读StackOverflow并将android:windowSoftInputMode =“ stateHidden | adjustResize”添加到AndroidManifest.xml中,但仍然无法正常工作。
What happens to be the problem and how can I fix it? 碰巧是什么问题,我该如何解决?
Please try to set android:layout_height="match_parent"
on the root element. 请尝试在根元素上设置
android:layout_height="match_parent"
。
Your root element has android:layout_height="wrap_content"
(calculate your height based on your children) and it's main child has android:layout_height="match_parent"
(calculate your height based on your parent). 您的根元素具有
android:layout_height="wrap_content"
(根据您的孩子计算身高),而主要孩子具有android:layout_height="match_parent"
(根据您的父母计算身高)。 It looks like chicken and egg problem and I suppose that's why it works on some devices and on some others it doesn't. 它看起来像是鸡肉和鸡蛋的问题,我想这就是为什么它可以在某些设备上运行,而在某些其他设备上却不行的原因。
To be honest, I haven't tried if this works, but that's what I concluded. 老实说,我还没有尝试过是否可行,但这就是我得出的结论。 If it doesn't help, I'll give it another look.
如果没有帮助,我再看一看。
已修复,问题是在LinearLayout中使用了上边距而不是为元素填充,这显然是一个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.