ImageView中的位图在屏幕上被裁剪掉

时间:2010-05-14 13:28:44

标签: java android bitmap imageview

我正在研究需要下载图像并在ImageView中显示的Android应用程序。 Bitmap传递给主java文件并添加到图像视图中,如下所示:

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

除了图像的左侧从屏幕上消失外,这是有效的。 ImageView位于ScrollView中,可保持正确的大小。这意味着ScrollView右侧有黑色空格,图像向左切断。

ImageView的XML是这样的:

<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>

知道为什么我的图像被切断了吗?

谢谢!

3 个答案:

答案 0 :(得分:5)

您是否尝试过设置android:scaleType =“center”而不是android:layout_gravity =“center”?

这将使图像在ImageView中居中而不进行缩放。

答案 1 :(得分:3)

机器人:scaleType = “centerCrop”

答案 2 :(得分:1)

最终对我有用的解决方案是将内部ImageView设置为具有比最大图像更大的固定高度和宽度,添加大量填充,然后在xml中设置android:scrollX和android:scrollY以获取图像放在我需要的地方。这解决了图像在水平滚动中被裁剪的问题。

相关问题