Android如何在滚动视图中填充相对布局到全屏

Android如何在滚动视图中填充相对布局到全屏,android,scrollview,android-relativelayout,Android,Scrollview,Android Relativelayout,我无法在全屏上填充我的相对布局。例如,当一个用户在底部创建另一个布局时,他将出现在最后一个布局之后。 这是我的密码 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context=".android_app_activity.EspacePersonnelActivit

我无法在全屏上填充我的相对布局。例如,当一个用户在底部创建另一个布局时,他将出现在最后一个布局之后。 这是我的密码

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".android_app_activity.EspacePersonnelActivity"
    android:layout_width="fill_parent"
    android:background="@drawable/ep_background"
    android:id="@+id/espacePersonnelLayout"
    android:layout_height="fill_parent">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >...

...

这很正常,一个滚动视图-只能有一个子-占据所有屏幕空间,因此您将添加的所有内容都将显示在最后。

这很正常,一个滚动视图-只能有一个子-占据所有屏幕空间,因此,您将添加的所有内容都将显示在最后。

始终保持scrollview子级的高度必须为wrap\u内容。要填充整个屏幕,可以使用滚动视图的fillViewport属性。下面是一个工作示例-

<LinearLayout 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:orientation="vertical"
    tools:context="com.example.jeshtamsru.tntrains.DashboarsActivity">
    <ScrollView
        android:layout_width="match_parent"
        android:fillViewport="true"
        android:layout_height="wrap_content">
        <LinearLayout android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <RelativeLayout
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:orientation="horizontal"
                 android:layout_gravity="center_horizontal">
                 <Button
                      android:layout_width="wrap_content"
                      android:width="300dp"
                      android:gravity="center"
                      android:layout_height="wrap_content"
                      android:text="chennai to coimbatore"/>
           </RelativeLayout>
          <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_gravity="center_horizontal">
            <Button
                android:layout_width="wrap_content"
                android:width="300sp"
                android:gravity="center"
                android:layout_height="wrap_content"
                android:text="chennai to coimbatore"/>
        </RelativeLayout>
    </LinearLayout>
 </ScrollView>
</LinearLayout>


希望它能帮助您:)

始终保持scrollview子级的高度必须是wrap\u内容。要填充整个屏幕,可以使用滚动视图的fillViewport属性。下面是一个工作示例-

<LinearLayout 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:orientation="vertical"
    tools:context="com.example.jeshtamsru.tntrains.DashboarsActivity">
    <ScrollView
        android:layout_width="match_parent"
        android:fillViewport="true"
        android:layout_height="wrap_content">
        <LinearLayout android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <RelativeLayout
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:orientation="horizontal"
                 android:layout_gravity="center_horizontal">
                 <Button
                      android:layout_width="wrap_content"
                      android:width="300dp"
                      android:gravity="center"
                      android:layout_height="wrap_content"
                      android:text="chennai to coimbatore"/>
           </RelativeLayout>
          <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_gravity="center_horizontal">
            <Button
                android:layout_width="wrap_content"
                android:width="300sp"
                android:gravity="center"
                android:layout_height="wrap_content"
                android:text="chennai to coimbatore"/>
        </RelativeLayout>
    </LinearLayout>
 </ScrollView>
</LinearLayout>

希望它能帮助你:)