How do you tell Android not to scale images?

这一生的挚爱 提交于 2019-12-30 11:17:10

问题


I have some pictures in the /drawable folder, which to my understanding is intepreted as /drawable-mdpi. Now these images are scaled when being used (depending on the device). I don't want to add more pictures, because they don't exist. And I don't have the resources to create different res pictures.

I just want the pictures to appear smaller on bigger devices. Is there a way of not scaling the images?

I'd hate to have to hard-code all the picture sizes.

This is the second question, as edits aren't attracting attention at all. Sorry about that.


回答1:


Adding the BitmapFactory.Options parameter to the decodeResource with the flag inScaled set to false is how to do it

BitmapFactory.Options mNoScale = new BitmapFactory.Options();
mNoScale.inScaled = false;
BitmapFactory.decodeResource(getResources(), R.drawable.id, mNoScale);



回答2:


What happens when you say layout_width="wrap_content" layout_height="wrap_content"?



来源:https://stackoverflow.com/questions/7330097/how-do-you-tell-android-not-to-scale-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!