java - ImageView 中的位图被裁剪出屏幕

标签 java android bitmap imageview

我正在开发一个 Android 应用程序,它需要下载图像并将其显示在 ImageView 中。位图被传递到主 java 文件并添加到 ImageView 中,如下所示:

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>

知道为什么我的图片被截断了吗?

谢谢!

最佳答案

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

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

关于java - ImageView 中的位图被裁剪出屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2834476/

相关文章:

java - Spring security 的@EnableWebSecurity 与 oauth 的@EnableResourceServer

java - 使用Uploadify时出错

java - 以毫秒为单位比较日期

bitmap - DICOM和DICOM叠加问题

Android 图形 : Changing the alpha of just an image (not the background)

javascript - 为什么 p :inputTextArea value is not set?

android - 在 android 中更改现有 db4o 中的类属性

java - 发生内存泄漏。无法检测泄漏并进行清洁

android - Android 2.2 日历

android - 从 Facebook 获取个人资料图片并将其显示在 Android 应用程序中