Search code examples
androidandroid-imageviewandroid-scrollview

ScrollView padding


I'm trying to use ScrollView with an ImageView in it. My xml code for it is this:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:layout_gravity="right" >

        <ImageView
            android:id="@+id/tapjoy_dialog_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:src="@drawable/untitled" />

</ScrollView>

Strangely, when I run it, the image shows up with a very-wide-padding on the top and bottom of it. To understand what I mean please take a look at the screenshot I attached.

ScrollView snapshot

How can I solve this?

More strangely:

  1. When I remove the ScrollView, and leave the ImageView only, it doesn't pad and work nicely.

  2. When I remove the ImageView and place a big textView instead it also doesn't pad and work nicely.

So, I think the problem is somewhat related to the combination of the ScrollView and the ImageView...

The image I try to put in the ImageView is this: enter image description here


Solution

  • Add android:adjustViewBounds="true" to your ImageView.