2014-10-05 87 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」