Question

I'm working on an Android application that needs to download an image and display it inside an ImageView. The Bitmap is passed to the main java file and added to the image view like this:

comic = (ImageView) findViewById(R.id.comic);
comic.setImageBitmap(c.getImageBitmap());

This works, except that the left side of the image disappears off the screen. The ImageView is in a ScrollView, which maintains the correct size. This means that there is black space to the right in the ScrollView and the image is cut off to the left.

The XML for the ImageView is this:

<ScrollView 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <HorizontalScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <ImageView 
            android:id="@+id/comic" 
            android:layout_height="fill_parent"
            android:layout_width="fill_parent" 
            android:layout_gravity="center"
            android:src="@drawable/xkcdlogo" />
    </HorizontalScrollView>
</ScrollView>

Any idea why my image is being cut off?

Thanks!

Was it helpful?

Solution

Have you tried setting android:scaleType="center" rather than android:layout_gravity="center"?

This will center the image in the ImageView without scaling.

OTHER TIPS

android:scaleType="centerCrop"

The solution that finally worked for me was to set the inner ImageView to have a fixed height and width larger than the largest image, add a lot of padding, and then set android:scrollX and android:scrollY in the xml to get the images placed where I needed them. This fixed the problem with the images getting cropped in the horizontal scroll.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top