Android-Relativelayout中ScrollView中的LinearLayout
|
我对布局有一点问题。
我制作了RelativeLayout,在其中放置了两个LinearLayouts(1和2),并在它们之间放置了ScrollView和LinearLayout。接下来,我将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)。
没有找到相关结果
已邀请:
3 个回复
稀瓣囊
滚动查看到
最后,我将ScrollView放入具有以下参数的新LinearLayout中:
因此,ScrollView及其子布局将按钮设置为水平居中,而外部LinearLayout将按钮设置为垂直居中。 :-)
系漏
的
更改为
,而不是
。
盛梯獭八搽