简体   繁体   English

Android ScrollView没有使用相对布局滚动

[英]Android ScrollView is not scrolling with a relative layout

I have the following xml layout but my scrollview is not scrolling when I run the app. 我具有以下xml布局,但是运行该应用程序时,scrollview没有滚动。 What am I doing wrong? 我究竟做错了什么? I am trying to use a Relative layout in the scrollview instead of a Linear Layout Here is the xml.. 我正在尝试在滚动视图中使用相对布局,而不是线性布局。这是xml。

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Medium Text"
            android:id="@+id/main_title"
            android:textSize="30sp"
            android:textStyle="bold"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <ImageView
            android:layout_width="180dp"
            android:layout_height="270dp"
            android:id="@+id/movie_poster"
            android:layout_weight="0.59"
            android:layout_below="@+id/main_title"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="30dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Ratings:"
            android:id="@+id/textView"

            android:layout_alignTop="@+id/movie_poster"
            android:layout_toRightOf="@+id/movie_poster"
            android:layout_toEndOf="@+id/movie_poster"
            android:layout_marginLeft="52dp"
            android:layout_marginStart="52dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text=" 6.5"
            android:textStyle="bold"
            android:id="@+id/movie_rating"
            android:layout_alignTop="@+id/textView"
            android:layout_toRightOf="@+id/textView"
            android:layout_toEndOf="@+id/textView" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text=" 2015-01-01"
            android:textStyle="bold"
            android:id="@+id/movie_release_date"
            android:layout_below="@+id/textView"
            android:layout_alignLeft="@+id/textView" />


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="180dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Medium Text"
            android:id="@+id/movie_description"
            android:layout_below="@+id/movie_poster"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />
    </RelativeLayout>
</ScrollView>

That is because you set the height of the ScrollView to fill_parent . 那是因为您将ScrollView的高度设置为fill_parent Try using a LinearLayout with weight so it fills the space left over from the other views. 尝试使用具有重量的LinearLayout ,以使其填充其他视图剩余的空间。

If you do not want to set it to a specific height, you can also add 如果您不想将其设置为特定高度,也可以添加

android:fillViewport="true"

to your ScrollView 到您的ScrollView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM