簡體   English   中英

如何在xml布局中添加兩個Scroll視圖,以使每個scrollview占據布局高度的一半?

[英]How can I add two Scroll views in a xml layout such that each scrollview take half of the height of the layout?

如何在android XML布局中添加兩個ScrollView,以使每個滾動視圖占據布局高度的一半?

在此處輸入圖片說明

您可以使用LinearLayout作為rootview,然后添加兩個ScrollView作為子視圖,並將android:layout_weight="1"分配給這兩個ScrollView

注意:如果要讓視圖水平滾動,請使用HorizontalScrollView

樣本代碼

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@android:color/black"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <!--add viw here-->
        </LinearLayout>

    </ScrollView>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@android:color/holo_red_dark"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <!--add viw here-->
        </LinearLayout>

    </ScrollView>


</LinearLayout>

OUTPUT

在此處輸入圖片說明

有多種方法可以做到這一點。 我建議您一種簡單的方法。 嘗試在父級布局中添加weightsum = 2。 並用這樣的1設計布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_rel"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="2.0" >

    <RelativeLayout
        android:id="@+id/child_one"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:background="#0000FF" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/child_two"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:background="#00FF00" >
    </RelativeLayout>

</LinearLayout>

暫無
暫無

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

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