繁体   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