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)。     
已邀请:
好的,我做到了。 我要做的就是将ScrollView内部的LinearLayout设置为
layout_width=\"wrap_content\"
layout_gravity=\"center_horizontal\"
android:orientation=\"vertical\"
滚动查看到
layout_width=\"fill_parent\"
layout_gravity=\"center_horizontal\"
layout_height=\"wrap_content\"
最后,我将ScrollView放入具有以下参数的新LinearLayout中:
layout_width=\"fill_parent\" 
layout_height=\"fill_parent\" 
gravity=\"center_vertical\" 
orientation=\"vertical\"
因此,ScrollView及其子布局将按钮设置为水平居中,而外部LinearLayout将按钮设置为垂直居中。 :-)     
尝试将
lin2
layout_width
更改为
wrap_content
,而不是
fill_parent
。     
试试这个代码,我认为这是最好的解决方案
  <HorizontalScrollView
   xmlns:android=\"http://schemas.android.com/apk/res/android\"
   android:layout_width=\"fill_parent\"
   android:layout_height=\"fill_parent\" android:orientation=\"vertical\" >
   </HorizontalScrollView>
    

要回复问题请先登录注册