[英]How can I add two Scroll views in a xml layout such that each scrollview take half of the height of the layout?
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.