开发者

Bitmap in ImageView is cropped off the screen

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" 
            andr开发者_如何学Coid: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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜