Android ImageView 中的全尺寸图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2537396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Full size image in ImageView
提问by benvd
I'm trying to draw an image in an ImageView, but i want it to be unscaled, with scrollbars as necessary. How can I accomplish this? Right now I just have a drawable set as the android:src of the ImageView in the XML. This autoscales the image to fit the screen width.
我正在尝试在 ImageView 中绘制图像,但我希望它不缩放,并根据需要使用滚动条。我怎样才能做到这一点?现在我只有一个 drawable 集作为 XML 中 ImageView 的 android:src 。这会自动缩放图像以适应屏幕宽度。
I read that this might be because of the compatibility mode (developing for 1.5, testing on 2.1), but then I added
我读到这可能是因为兼容模式(为 1.5 开发,在 2.1 上测试),但后来我添加了
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4" />
to my manifest, and nothing changed.
到我的清单,没有任何改变。
Any clues?
有什么线索吗?
--
——
Edit: I used android:scaleType="center"
on the ImageView, and this displays the full image (can't believe I didn't see this before), but I still only get a vertical scrollbar. Using android:scrollbars="horizontal"
on the ScrollView that's wrapped around the ImageView (obviously) hides the vertical scrollbar, but doesn't show a horizontal scrollbar...
编辑:我android:scaleType="center"
在 ImageView 上使用过,这显示了完整图像(不敢相信我以前没有看到过),但我仍然只得到一个垂直滚动条。android:scrollbars="horizontal"
在环绕 ImageView 的 ScrollView 上使用(显然)隐藏垂直滚动条,但不显示水平滚动条...
回答by jmrlegido
This worked for me (using an HorizontalScrollView inside a ScrollView):
这对我有用(在 ScrollView 中使用 HorizontalScrollView):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imagen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
/>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
回答by Robby Pond
I believe you have to size the ImageView to the size of the Bitmap and place the ImageView into a ScrollView. But you may run into memory issues trying to display a large image.
我相信您必须将 ImageView 的大小调整为 Bitmap 的大小,并将 ImageView 放入 ScrollView。但是您在尝试显示大图像时可能会遇到内存问题。