Android ScrollView内部的RelativeLayout不';不要滚动。我';我做错了?

Android ScrollView内部的RelativeLayout不';不要滚动。我';我做错了?,android,android-layout,scrollview,android-relativelayout,Android,Android Layout,Scrollview,Android Relativelayout,我正试图使滚动的景观布局。我将我的RelativeLayout放在滚动视图中,但什么也没发生。代码如下: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ScrollView01" android:layout_width="match_parent" android:layout_height="wrap_content" android:fillViewpor

我正试图使滚动的景观布局。我将我的
RelativeLayout
放在
滚动视图中,但什么也没发生。代码如下:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:gravity="center_horizontal">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/green_light"
    tools:context="app.example.ui.SplashActivity">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/parent_center"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/logo" />

    <View
        android:id="@+id/parent_center"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_centerInParent="true" />

    <LinearLayout
        android:id="@+id/ll_gateway_discovery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/parent_center"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/registration"
            android:textSize="@dimen/text_large"
            android:textStyle="bold" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/who_are_you"
            android:textColor="@color/grey_dark"
            android:textSize="@dimen/text_normal"
            android:textStyle="bold" />

        <EditText
            android:id="@+id/et_username"
            android:layout_margin="8dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="240dp"
            android:hint="@string/prompt_email"
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:singleLine="true"
            android:textSize="@dimen/text_normal" />

        <EditText
            android:id="@+id/et_password"
            android:layout_margin="8dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="240dp"
            android:imeActionId="@+id/login"
            android:imeActionLabel="@string/action_sign_in_short"
            android:imeOptions="actionUnspecified"
            android:inputType="textPassword"
            android:maxLines="1"
            android:singleLine="true"
            android:text="pippo"
            android:hint="@string/password"
            android:textSize="@dimen/text_normal" />

        <ImageView
            android:id="@+id/btn_login"
            android:layout_marginTop="4dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_submit" />
    </LinearLayout>
</RelativeLayout>


我做错了什么?这让我发疯:)

使用
HorizontalScrollView
而不是
ScrollView
,因为正常的ScrollView只是垂直滚动


并且scrollView子级的宽度/高度为wrapContent。。对于horizontalScrollView width

而言,问题在于您使用的是match\u parent,而不是wrap\u content作为RelativeLayout的布局宽度和布局高度。例如,如果要垂直滚动,则必须使用以下选项:

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
这样,RelativeLayout的宽度将与ScrollView相同,但高度将与其中的视图一样大

结果xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/ScrollView01"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:gravity="center_horizontal" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/green_light"
        tools:context="app.example.ui.SplashActivity" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/parent_center"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/logo" />

        <View
            android:id="@+id/parent_center"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_centerInParent="true" />

        <LinearLayout
            android:id="@+id/ll_gateway_discovery"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/parent_center"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/registration"
                android:textSize="@dimen/text_large"
                android:textStyle="bold" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/who_are_you"
                android:textColor="@color/grey_dark"
                android:textSize="@dimen/text_normal"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/et_username"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:hint="@string/prompt_email"
                android:inputType="textEmailAddress"
                android:maxLines="1"
                android:minWidth="240dp"
                android:singleLine="true"
                android:textSize="@dimen/text_normal" />

            <EditText
                android:id="@+id/et_password"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:hint="@string/password"
                android:imeActionId="@+id/login"
                android:imeActionLabel="@string/action_sign_in_short"
                android:imeOptions="actionUnspecified"
                android:inputType="textPassword"
                android:maxLines="1"
                android:minWidth="240dp"
                android:singleLine="true"
                android:text="pippo"
                android:textSize="@dimen/text_normal" />

            <ImageView
                android:id="@+id/btn_login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="4dp"
                android:background="@drawable/btn_submit" />
        </LinearLayout>
    </RelativeLayout>

</ScrollView>


使用Linearlayout而不是relativeLayout

无需执行任何操作。它不起作用。在相对论中,你有一个线性的解释,它到底是如何不起作用的?我编辑了我的答案以提供更多细节。您要向哪个方向滚动?你确定RelativeLayout内的视图超出了ScrollView的大小吗?我想垂直滚动横向布局你什么意思不做?如果你不给我更多的信息,我只能猜测。首先,发布完整的布局xml,它肯定有其他问题。我已经发布了整个布局