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

How do I add two ScrollViews in an android XML-layout such that each scroll view takes half of the height of the layout? 如何在android XML布局中添加两个ScrollView,以使每个滚动视图占据布局高度的一半?

在此处输入图片说明

You can use LinearLayout as rootview then add two ScrollView as child and assign android:layout_weight="1" to both ScrollView 您可以使用LinearLayout作为rootview,然后添加两个ScrollView作为子视图,并将android:layout_weight="1"分配给这两个ScrollView

Note : if you want your view scroll horizontally then use HorizontalScrollView 注意:如果要让视图水平滚动,请使用HorizontalScrollView

SAMPLE CODE 样本代码

<?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 OUTPUT

在此处输入图片说明

There is a multiple way to do this. 有多种方法可以做到这一点。 I am suggesting you one simple way. 我建议您一种简单的方法。 try to add weightsum =2 inside parent layout. 尝试在父级布局中添加weightsum = 2。 And devide layout with 1 like this 并用这样的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.

相关问题 如何在相对布局或任何布局中动态添加视图 - How can I add Views dynamically in a Relative layout or in any Layout 如何将Scrollview布局分成两部分以显示父背景颜色和两个窗格? - How do I split a Scrollview layout in half to show parent background color and two panes? 如何为该布局添加ScrollView? - How to add ScrollView for this layout? 如何将现有的xml布局添加到由代码创建的布局中 - How can I add an existing xml layout to a layout that created by code 如何添加布局文件仅占用Android活动的一半页面 - How to add a layout file to only take half the page of Android activity 如何动态将布局和视图添加到Android XML布局文件? - How can I dynamically add layouts and views to an Android XML layout file? 如何将ScrollView添加到约束布局? - How do I add a ScrollView to a constraint layout? 我可以以编程方式获取xml布局并重用它吗? - Can I programmatically take a xml layout and reuse it? 如何访问页脚xml布局内的视图? 安卓系统 - How can I access the views inside of a footer xml layout? Android 如何让recyclelerView在android约束布局中占用最多一半的屏幕(最大值)? - How can I make a recyclerView to take up to half the screen(max) in android constraint layout?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM