android - 在 ScrollView 中使用 RelativeLayout 不会产生滚动

标签 android android-layout scrollview android-relativelayout

我正在尝试让我的相对布局滚动。我将 ScrollView 添加为父 View ,但是当我将手机或模拟器倾斜到水平时,它不会滚动。

我尝试了几种不同的解决方案,但似乎都不起作用。 一些包括: No scrolling in scrollview , ScrollView not Working - Relative Layout , 和 RelativeLayout with scrollview not scrolling

代码如下:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:fillViewport="true"
    android:scrollbars="none">
<RelativeLayout

    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="vertical">

        <Button
            android:layout_width="200dp" 
            android:id="@+id/register_button"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:text="Register" />

        <EditText
            android:id="@+id/email2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/register_button"
            android:layout_alignLeft="@+id/register_button"
            android:layout_alignRight="@+id/register_button"
            android:hint="Re-Enter Email"
            android:inputType="textEmailAddress" />

        <EditText
            android:id="@+id/email1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/email2"
            android:layout_alignLeft="@+id/email2"
            android:layout_alignRight="@+id/email2"
            android:hint="Email"
            android:inputType="textEmailAddress" />

        <EditText
            android:id="@+id/password2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/email1"
            android:layout_alignLeft="@+id/email1"
            android:layout_alignRight="@+id/email1"
            android:hint="Repeat Password"
            android:inputType="textPassword" />

        <EditText
            android:id="@+id/password1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/password2"
            android:layout_alignLeft="@+id/password2"
            android:layout_alignRight="@+id/password2"
            android:hint="Password"
            android:inputType="textPassword" />

        <EditText
            android:id="@+id/lastName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/password1"
            android:layout_alignLeft="@+id/password1"
            android:layout_alignRight="@+id/password1"
            android:hint="Last Name"
            android:imeOptions="actionNext"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/firstName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/lastName"
            android:layout_alignLeft="@+id/lastName"
            android:layout_alignRight="@+id/lastName"
            android:hint="First Name"
            android:imeOptions="actionNext"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/userName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/firstName"
            android:layout_alignLeft="@+id/firstName"
            android:layout_alignRight="@+id/firstName"
            android:hint="Username"
            android:imeOptions="actionNext"
            android:inputType="textPersonName" />




</RelativeLayout>
</ScrollView>

谢谢!

最佳答案

您的 RelativeLayout 设置为 fill_parent。如果它的大小与其 ScrollView 父级相同,则没有可滚动的内容。将其设为 wrap_content 并正确布局其子项以暗示高度。

关于android - 在 ScrollView 中使用 RelativeLayout 不会产生滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10020474/

相关文章:

android - 将 Android 布局从相对更改为线性

android - 如何获得用户滚动的百分比?

c++ - 在 QT "ui->scrollArea->horizontalScrollBar()->setValue(0)"中没有作用

android - 谷歌播放 IAP 错误 1003 :Purchase signature verification failed - using Corona SDK

android - 如何测试 NFC 应用程序?

java - HttpClient 在果冻 bean 中不起作用?

android - 在 Android 中使 EditText 和 Button 的高度相同

android - OpenCV,Java:特定区域中的颜色检测

android - 在 Android 上为自定义形状添加阴影

iOS - scrollViewDidEndDecelerating 为 scrollView 和 collectionView 运行