英文:
ImageView Scaling for No Apparent Reason
问题
我正在使用Android Studio,在activity_main.xml中创建了一个ImageView。布局的宽度和高度设置为"match_parent"。scaleType设置为"center",源图像为70x70像素。当我在模拟器中运行应用程序时,图像在屏幕上显示的尺寸大于70x70像素。我的意思是它在手机屏幕上占用的空间超过了70x70像素。我不知道为什么会这样。该应用程序专门处于横向模式,这可能与问题相关。如果我包含了不必要的细节,请原谅,我真的不知道哪些信息是相关的。我打算使图像在手机屏幕上占据70x70像素的空间。是什么原因导致了这种意外的结果,我应该如何修复?
英文:
I'm using Android Studio, and have created an ImageView in activity_mail.xml. The layout width and height are set to "match_parent". The scaleType is set to "center" and the source image is 70x70 pixels. When I run the app in the emulator the Image appears on the screen larger than 70x70 pixels. I mean it takes up more than 70x70 pixels on the screen of the phone. I don't know why it's doing this. The app is exclusively in Landscape mode, that might be relevant. Forgive me if I have included extraneous details, I genuinely don't know what information would be relevant to include. I intend to make it so that the image takes up 70x70 pixels on the screen of the phone. What is causing the unintended result, and how could I fix it?
答案1
得分: 0
修改ScaleType
,也许使用fit_center
代替仅使用center
+ android:adjustViewBounds="true"
会符合您的需求...另一种方式是创建具有wrap_content
大小的ImageView
,放置在某个容器中(例如RelativeLayout
),具有match_parent
大小。
还可以查看这个关于ScaleType
的可视化指南。
请注意,在具有高清分辨率的设备上,70像素的图像会很大,在具有全高清分辨率的设备上会小得多。您应该在适当的密度桶(mdpi
,hdpi
等)中拥有图像的几个版本,或者如果您的图像来自某个API,只需下载适当的大小,这样您就可以说您拥有具有70dp
尺寸的图像,而不是70px
。
英文:
change ScaleType
, maybe fit_center
instead of just center
+ android:adjustViewBounds="true”
will fit your purposes... another way is to create ImageView
with wrap_content
sizes placed in some container (e.g. RelativeLayout
) with match_parent
sizes
also check this visual guide for ScaleType
note that 70px image will be big on devices with HD resolution and significantly smaller on those with e.g. full HD. you should have few versions of your image in proper density buckets (mdpi
, hdpi
etc.) or just download proper size if your image comes frome some API, so then you can say that you have image with 70dp
dimension, not 70px
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论