Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollView goes on top of another layout Android

In the following code I've got two main containers, a RelativeLayout and a ScrollView. I need the RelativeLayout to be on top fixed and below that I need the ScrollView with Images to be scrollable. I've got the following two questions:

  1. Though my ScrollView is scrollable but it goes on top of the RelativeLayout. !important
  2. The view of my images present within the vertical LinearLayout are thumbnail sized. If I have 15-20 images, they take a lot of vertical space. How do I have the images to fit the maximum in a row based on the screen size and then go to the next row?

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
        </LinearLayout>
    </RelativeLayout>
    
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <ImageView>
            </ImageView>
    
            <ImageView>
            </ImageView>
    
            <ImageView>
            </ImageView>
    
            <ImageView>
            </ImageView>
    
        </LinearLayout>
    </ScrollView>
    

2 Answers

Follow these in simple way:

  1. You need to use a fixed height for the parent, i.e., <RelativeLayout>.
  2. Set the height of the ScrollView to match_parent.
  3. Make sure you put everything inside a LinearLayout.

Finally you would end up with this:

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    </RelativeLayout>
</LinearLayout>
like image 89
Praveen Kumar Purushothaman Avatar answered Jan 20 '26 18:01

Praveen Kumar Purushothaman


First, you can set your RelativeLayout's height to a fixed value. Then set your ScrollView's height to match_parent, so it takes up all the available space. Then both of these should be contained in a vertical LinearLayout, to avoid any overlapping.

like image 43
aljo f Avatar answered Jan 20 '26 19:01

aljo f