2014-10-05 88 views
0

我想添加一个滚动条到我的RelativeLayout,它包含5个ImageViews。可滚动的相对布局与ImageViews

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="XXX" > 

<ScrollView 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:scrollbars="horizontal" > 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ImageView 
     android:id="@+id/picture_imgvw_pic1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="showPictureZoomDialog" 
     android:src="@drawable/XXX"/> 

    <ImageView 
     android:id="@+id/picture_imgvw_pic2" 
     android:layout_toRightOf="@+id/picture_imgvw_pic1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="showPictureZoomDialog" 
     android:src="@drawable/XXX"/> 

    <ImageView 
     android:id="@+id/picture_imgvw_pic3" 
     android:layout_toRightOf="@+id/picture_imgvw_pic2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="showPictureZoomDialog" 
     android:src="@drawable/XXX"/> 

    <ImageView 
     android:id="@+id/picture_imgvw_pic4" 
     android:layout_toRightOf="@+id/picture_imgvw_pic3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="showPictureZoomDialog" 
     android:src="@drawable/XXX"/> 

    <ImageView 
     android:id="@+id/picture_imgvw_pic5" 
     android:layout_toRightOf="@+id/picture_imgvw_pic4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="showPictureZoomDialog" 
     android:src="@drawable/XXX"/>     

</RelativeLayout> 
</ScrollView> 

<Button 
    android:id="@+id/picture_button_next" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:text="@string/picture_button_next" 
    android:onClick="buttonNext"/> 

</RelativeLayout> 

这让我显示了5个ImageViews中的4个,没有什么可滚动的。我错过了什么?也许像“可见属性”的东西? thx :)

+0

它看起来像你的一些XML是失踪。请发布您的布局文件的其余部分 – bmat 2014-10-05 16:42:01

回答

0

问题是您的RelativeLayout的高度。它被设置为“match_parent”。你应该把它设置为“WRAP_CONTENT”像这样:

<ScrollView 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:scrollbars="horizontal" > 

    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

当设置为match_parent,该RelativeLayout的永远不会比滚动型高,因此没有滚动是可能的。

编辑:显然,你要那么你应该使用一个Horizo​​ntalScrollView而不是滚动型,水平滚动这是你的RelativeLayout的宽度应该是“WRAP_CONTENT”