How do you tell Android not to scale images?

2019-02-19 11:04发布

问题:

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"?