簡體   English   中英

Android如何將滾動視圖內的相對布局填充到全屏

[英]Android how to fill a relative layout inside scroll view to full screen

我無法在全屏上填充我的相對布局。 例如,當在底部進行另一個布局時,他只會出現在最后一個布局之后。 這是我的代碼

<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"
    >...

正常情況下,一個滾動視圖(只能有一個子視圖)占據了所有屏幕空間,因此您要添加的所有內容都會顯示在最后。

始終保持滾動視圖的子級的高度必須為wrap_content。 要填充整個屏幕,可以使用滾動視圖的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>

希望它能對您有所幫助:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM