dev90
dev90

Reputation: 7539

What is the resolution of default layout in Android?

I am just using simple default layout and not adding any of these layout versions; l-dpi-Layout,m-dpi-layout etc.. then what exactly the resolution of my default layout is?

Let say i add an image and define its width-height as 20dp X 20dp. This image is looking perfect in layout Preview screen, but would it look same in 1440X2560 screen or 1920X1080 screen.

My concerns are:

  1. what exactly is the resolution of default layout is?
  2. How would android know that the 20 dpi i am defining fits best for 1080X1920 resolution and 27dpi fits best 1440X2560 screen, when i am writing 20dpi in my default layout which perfectly fits in layout preview screen

Upvotes: 1

Views: 3140

Answers (2)

Rafay Ali
Rafay Ali

Reputation: 742

  1. By default when you create a template app, your main content layout has two parameters values as layout_width=match_parent and layout_height=match_parent. match_parent value means whatever the screen dpi size the mobile has, it stretches all the way to its size of width and height respectively which is calculated by android automatically when it runs its layout pass to position views (including padding). So in this context the default resolution of your layout is what your mobile has minus the size of statusBar and navigationBar.
  2. Android translates the DPI value you enter for your width and height into number of pixels internally to size your views. You can also put the size of your view into number of pixels but its not recommended.

Upvotes: 1

Jorge Torres
Jorge Torres

Reputation: 1886

The system assumes a target device with a density of 160dpi. When you define the size of yout image with dp unit, Android adapts the size according with the resolution of the device. For example, if you put an image of 100dp x 100dp in a 160dpi device it will take 100 x100 pixels, but in a device with a 640dpi screen it will take 400 x 400 pixel

Upvotes: 3

Related Questions