Avlas299 Avlas299 - 2 months ago 22
Android Question

How do i put multiple images(ImageView) in a ScrollView?

i want to put multiple images and scroll down and see them all. I tried to put a ScrollView and inside a ImageView but i dont know if i need to put a layout. I searched tutorials but i didnt found what i needed.

Answer

That's clearly not how ScrollViews work. ScrollView is a ViewGroup, so you have to put it outside the view that you want to scroll.

Also, there can only be one view as the direct child of scroll view. So you cannot do this:

<ScrollView>
    <ImageView>
    <ImageView>
    <ImageView>
</ScrollView>

Actually, you should put the images in a LinearLayout, and put the LinearLayout in the scroll view.

<ScrollView>
    <LinearLayout>
        <ImageView>
        <ImageView>
        <ImageView>
    </LinearLayout>
</ScrollView>

Note: the attributes are omitted because I'm lazy :P

EDIT:

If you want to scroll down, just set the orientation attribute to "vertical".

<ScrollView>
    <LinearLayout
        android:orientation="vertical"
        other attributes.../>
            image views here...
    </LinearLayout
</ScrollView>
Comments