Brahadeesh
Brahadeesh

Reputation: 2255

android XML scrollview and linear layout problem


I have the following code:

<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <LinearLayout android:orientation="vertical" 
                  android:layout_width="fill_parent" 
                  android:layout_height="fill_parent">

        <ImageView android:src="@drawable/ducks_r2_c1"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" />
        <ImageView android:src="@drawable/ducks_r3_c1"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" android:clickable="true"/>
        <ImageView android:src="@drawable/ducks_r4_c1"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" android:clickable="true"/>
        <ImageView android:src="@drawable/ducks_r5_c1"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" android:clickable="true"/>
        <ImageView android:src="@drawable/ducks_r6_c1"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content" android:clickable="true"/>

    </LinearLayout>

</ScrollView>

I have used layout_width="fill_parent" everywhere. But this is the screenshot of how it shows up on the emulator.
enter image description here
I dont want the space on either side of the images.
Why is it showing up like this? How can I rectify it?
Thank you

Upvotes: 2

Views: 4792

Answers (2)

Paulo
Paulo

Reputation: 1041

I guess this is happening because the image is not streching.

You may try to ask the image to strech itself:

android:scaleType="fitXY"

or use it as background.

please check this thread: android: stretch image in imageview to fit screen

Upvotes: 1

Codeman
Codeman

Reputation: 12375

A ScrollView will only inflate to as many items are in it.

You should be able to solve this by using a LinearLayout (or another more predictable layout) as the parent for your ScrollView with android:layout_height="match_parent" and setting the ScrollView to android:layout_height="wrap_content" and the same for layout_width on both.

Upvotes: 0

Related Questions