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!
Have you tried setting android:scaleType=”center” rather than android:layout_gravity=”center”?
This will center the image in the ImageView without scaling.