【发布时间】:2016-05-30 20:41:18
【问题描述】:
我在 Android Studio 中有以下 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>
当键盘未启动时,我可以看到每个元素,但每当键盘启动时,ScrollView 不会向下滚动以显示被覆盖的元素。我已通读 StackOverflow 并将 android:windowSoftInputMode="stateHidden|adjustResize" 添加到 AndroidManifest.xml 但它仍然无法正常工作。
发生了什么问题,我该如何解决?
【问题讨论】:
-
我刚刚在一个测试项目中尝试了你的布局。它为我滚动,即使没有
adjustResize。您可以在其他设备或模拟器上尝试吗?您是否有任何机会在调试器中暂停? -
@MarcinKoziński 我在 3 台设备上试用过,两台 pre-Lollipop 和一台运行 vanilla Android M,它只适用于 1。这很奇怪。
-
尝试去掉ScrollView里面的RelativeLayout。这不是必需的,尽管它也应该与它一起使用。
标签: android android-layout android-xml android-scrollview