someengr
someengr

Reputation: 690

ScrollView doesn't Scroll

I have a ScrollView in a FrameLayout. ScrollView has a single child LinearLayout. I am adding ImageViews to this LinearLayout programmatically. I want scrollview to scroll horizontally.

<FrameLayout 
                        android:id="@+id/imgScroll"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/avatar_block">

                        <ScrollView
                            android:id="@+id/avatarScrollView"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" 
                            android:layout_gravity="center" 
                            android:fillViewport="true"> 

                            <LinearLayout
                                android:id="@+id/scrollLayout"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content" 
                                android:gravity="left">


                            </LinearLayout>
                        </ScrollView>

                        <RelativeLayout 
                         android:layout_width="match_parent"
                             android:layout_height="match_parent">
                                     <!-- 2 ImageViews -->
                        </RelativeLayout>
    </FrameLayout>

This is how I am adding ImageViews (Currently hardcoding the images to drawables)

LinearLayout inScrollLayout = (LinearLayout) findViewById(R.id.scrollLayout);
for(int i = 0; i < imgArray.length; i++)
{
    ImageView imgView = new ImageView(this);
    imgView.setImageResource(R.drawable.icon);  
    imgView.setPadding(0, 0, 40, 0);
    inScrollLayout.addView( imgView);
}

ImageViews are added to the layout, but the last image shrinks it's size and I can not scroll.

Upvotes: 3

Views: 1175

Answers (1)

Khantahr
Khantahr

Reputation: 8548

ScrollView doesn't scroll horizontally, you need HorizontalScrollView.

Upvotes: 7

Related Questions