简体   繁体   中英

How to make ScrollView with a RelativeLayout with multiple child layouts fill the screen?

I have a layout that has just a ScrollView visible. It has a relative layout as its child. This layout has several other layouts (mainly text views) as its children. When the text is not big enough, the scroll view does not expand itself to fit the whole screen. Instead, it shows a gap at the bottom where the background shows. I tried setting fillViewPort=true on the ScrollView, but that just made the first child layout (RL1) to fill the screen.

<?xml version="1.0" encoding="utf-8"?>
  <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_image">

   <ProgressBar android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="gone"/>

    <ScrollView
      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="wrap_content"
        android:paddingTop="10px">

      <RelativeLayout android:id="@+id/list"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:paddingTop="10px">

        <!-- This layout is filling the screen if I set fillViewPort="true" -->
        <RelativeLayout  android:id="@+id/RL1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            <!--TextViews and ImageViews -->

       </RelativeLayout>

        <RelativeLayout android:id="@+id/RL2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            <!--TextViews and ImageViews -->

        </RelativeLayout>

        <RelativeLayout android:id="@+id/RL3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

            <!--TextViews and ImageViews -->

        </RelativeLayout>

        <RelativeLayout  android:id="@+id/RL4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            <!--TextViews and ImageViews -->

        </RelativeLayout>

     </RelativeLayout>

   </RelativeLayout>

  </ScrollView>

</FrameLayout>

fillViewPort应该是fillViewport

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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