你需要一个线性布局,android:orientation="vertical"
.
然后将两个视图 (和ImageView
)ScrollView
添加android:layout_weight="80"
为ImageView
和android:layout_weight="20"
。ScrollView
两者都必须android:layout_height="0dip"
确定,只有重量很重要。
XML 代码如下所示(我使用了第二个 ImageView 而不是 ScrollView 来以蓝色和红色显示结果)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="80"
android:src="#FF0000FF" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="20"
android:src="#FFFF0000" />
编辑:要用图像填充背景,您有两种方法:
- 的简单集合
android:backround="<your drawable resoure>"
。LinearLayout
您唯一可能会松动的是可以在背景中居中和调整可绘制对象的大小。ImageView 在这一点上有更多的可能性。
因此,第二种方法是使用FrameLayout
. 它很轻巧,基本上根本没有定位。只需将所有元素放在一起。XML 如下所示:
<!-- This is your fixed view, e.g. with header information -->
<ImageView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="80"
android:src="@android:color/transparent" />
<!-- This would be your scroll view, e.g. for detail information -->
<ImageView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="20"
android:src="#FFFF0000" />