ScrollView仅适用于屏幕的一部分

时间:2011-10-06 18:51:47

标签: android scrollview relativelayout

我在将屏幕划分为两部分时遇到了一些麻烦。我不知道从哪里开始。到目前为止,我的所有布局都使用了RelativeLayout。基本上,我希望在屏幕的前70%(左右)中有一个可滚动的视图,在屏幕的底部30%(左右)中有两个按钮。 scrollview将填充几个textViews。这是我的准系统代码:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/stonerepeat"
android:gravity="center_horizontal"
>








<Button
android:id="@+id/back"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Looks good"
android:layout_alignParentBottom="true" 
android:layout_alignParentLeft="true" 
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" 
android:layout_marginBottom="10dp"
>
</Button>
<Button
android:id="@+id/stats"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hero Stats"
android:layout_alignLeft="@+id/back"
android:layout_alignRight="@+id/back" 
android:layout_above="@+id/back"
android:layout_marginBottom="3dp"
>
</Button>


</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

如果你想要百分比,最简单的方法是使用LinearLayout和权重。类似的东西:

<LinearLayout android:orientation="vertical" ...>
    <ScrollView android:layout_weight="7" ... />
    <RelativeLayout android:layout_weight="3" ...>
        <Button ... />
        <Button ... />
    </RelativeLayout>
</LinearLayout>
相关问题