good_evening
good_evening

Reputation: 21759

How to show an image proportional to the screen

I want to display .png image on TextView. Someone will use tablet, someone will use smartphone, how can I show an image proportional to the screen? Do I have to create different images and use in the code something like if(screen == smartphone) setView(Png1.png)?

Upvotes: 0

Views: 267

Answers (1)

karn
karn

Reputation: 6033

There are two important parameters which needs to taken cared when you are designing an app which
should run on multiple devices:

  • size(physical size of the device)
  • density of the device

Size: Size of a device in android is not defined as a unique physical value but as a range.
These are: small, normal, large and xlarge.

Density: Density is also defined as a range.
These are: ldpi, mdpi, hdpi and xhdpi.

enter image description here

For handling size you need to use have multiple layouts, one for each category of the size and you need to use different dp value for the height and width of the views for each of the layout as the sizeof a small and a large device will not be same.

For handling density you need to using different drawables for different screen densities i.e you need to place different density drawables in different drawable folders.
Eg:
These are the resolutions for a particular drawable

  • 36x36 for low-density (placed in drawable-ldpi)
  • 48x48 for medium-density (placed in drawable-mdpi)
  • 72x72 for high-density (placed in drawable-hdpi)
  • 96x96 for extra high-density (placed in drawable-xhdpi)

The ratio for this variation of the resolution is 3:4:6:8(ldpi:mdpi:hdpi:xhdpi)

For further reading you can refer to this android developer's link:
http://developer.android.com/guide/practices/screens_support.html

Upvotes: 2

Related Questions