[英]Bitmap in ImageView is cropped off the screen
我正在开发一个需要下载图像并将其显示在ImageView中的Android应用程序。 将位图传递到主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>
知道为什么我的图片被剪掉了吗?
谢谢!
您是否尝试过设置android:scaleType =“ center”而不是android:layout_gravity =“ center”?
这将使图像在ImageView中居中而不缩放。
android:scaleType =“ centerCrop”
最终对我有用的解决方案是将内部ImageView设置为具有比最大图像更大的固定高度和宽度,添加大量填充,然后在xml中设置android:scrollX和android:scrollY来放置图像我需要他们的地方。 这解决了图像在水平滚动中被裁剪的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.