Snake
Snake

Reputation: 14678

Loading image to ImageView and having it occupy certain space

I have an image that is say 45 by 45 pixel and I have it scaled appropriately in the 3 different drawable folder. Now when just load it on the screen it looks bigger than I want. If I want it to be smaller, what should I do? I really don't want to change the pixels of the original image. Is there any other solution (like controlling how much space it takes from XML)?

Thank you so much

EDIT: Just more clarification and specific question, How can I make an image occupy say 5% of the screen size irrelevent of the original size of the .png image?

Upvotes: 0

Views: 426

Answers (2)

Sandeep
Sandeep

Reputation: 1814

You can not specify what percent of screen should be occupied by the image. You can do one thing. Specify the different dimension in values folders and specify size there.

Upvotes: 0

MaciejGórski
MaciejGórski

Reputation: 22232

You can have ImageView occupying 5% by putting it in a LinearLayout with another View, setting both views layout_width to 0dp and layout_weight to 5 and 95 appropriately.

When doing so I would also suggest using 9-patch to not have weirdly looking stretches.

Upvotes: 1

Related Questions