How do I prevent scaling in Android Imageview?(如何防止在 Android Imageview 中缩放?)
问题描述
我有一张 480 x 40 像素的图像.我想在 ImageView 中显示此图像,而无需缩放以适应.
I have an image that is 480 pixels by 40 pixels. I would like to show this image in an ImageView without having it scale to fit.
例如:如果我的屏幕只有 320 像素宽,我希望只有 320 像素的图像显示在屏幕上,而不是让它自己塞进 ImageView(即使这意味着图像的其余部分被截断).
Ex: If my screen is only 320pixels wide I would like only 320pixels of the image to show on the screen, not have it cram itself into the ImageView (even if it means that the rest of the image gets cut off).
有没有办法防止它缩放以适应?
Is there a way to prevent it from scaling to fit?
另外,我希望图像的左侧与设备屏幕的左侧对齐.
Also, I would like the left side of the image to line up with the left side of the device's screen.
谢谢
推荐答案
使用ScaleType.CENTER
,像XML这样:
android:scaleType="center"
这将使图像在视图中居中,但不执行缩放"
This will "center the image in the view, but perform no scaling"
在此处阅读更多信息:http://developer.android.com/参考/android/widget/ImageView.ScaleType.html
(顺便说一句,这是谷歌搜索imageview scale"的第一次点击)
(This is by the way the first hit on googling "imageview scale")
这篇关于如何防止在 Android Imageview 中缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何防止在 Android Imageview 中缩放?


- Android - 拆分 Drawable 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01