【发布时间】:2011-04-14 18:08:47
【问题描述】:
我的布局有点问题。 我制作了 RelativeLayout,在其中放置了两个 LinearLayout(1 和 2),并在它们之间放置了带有 LinearLayout 的 ScrollView。接下来,我将该 ScrollView 设置为放置在 linearLayout2 之下和 linearLayout1 之上。但是 ScrollView 内部的 LinearLayout 没有设置为它的父级。
这里是代码,也许我犯了一个错误:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dip"
android:layout_alignParentTop="true"
android:id="@+id/lin1"
android:layout_weight="1">
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_weight="1" android:id="@+id/lin3"
android:layout_height="60dip">
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="horizontal"
android:layout_below="@id/lin1"
android:layout_above="@id/lin3" android:id="@+id/ScrollView">
<LinearLayout
android:layout_width="fill_parent"
android:orientation="vertical"
android:id="@+id/lin2"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal">
<Button android:text="@string/button1"
android:id="@+id/button1"
android:layout_gravity="center"
android:layout_width="280dip"
android:layout_height="60dip">
</Button>
<Button android:text="@string/button2"
android:id="@+id/button2"
android:layout_gravity="center"
android:layout_width="280dip"
android:layout_height="60dip">
</Button>
<Button android:text="@string/button3"
android:id="@+id/button3"
android:layout_gravity="center"
android:layout_width="280dip"
android:layout_height="60dip">
</Button>
<Button android:text="@string/button4"
android:id="@+id/button4"
android:layout_gravity="center"
android:layout_width="280dip"
android:layout_height="60dip">
</Button>
</LinearLayout>
</ScrollView>
任何想法,为什么 ScrollView 内的 LinearLayout 比 ScrollView 大?
编辑: 到目前为止,我注意到当我设置 layout_gravity="center_vertical" 时,ScrollView 内部的 LinearLayout 会移到外面。看起来设置中心是指主布局(RelativeLayout)。
【问题讨论】:
标签: android scrollview android-linearlayout android-relativelayout