ImageView 中的位图被裁剪出屏幕
我正在开发一个 Android 应用程序,需要下载图像并将其显示在 ImageView 中。位图被传递到主 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>
知道为什么我的图像被截断吗?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过设置 android:scaleType="center" 而不是 android:layout_gravity="center" ?
这将使图像在 ImageView 中居中而不缩放。
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"
android:scaleType="centerCrop"
最终对我有用的解决方案是将内部 ImageView 设置为具有比最大图像大的固定高度和宽度,添加大量填充,然后在 xml 中设置 android:scrollX 和 android:scrollY 以放置图像我需要他们的地方。这解决了图像在水平滚动中被裁剪的问题。
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.