Tanque
Tanque

Reputation: 113

Understanding what "dp" works on different screen dimensions

Imagine that I have a .png file with dimensions of 1280x1550px and I make a .xml file with that .png with the following characteristics:

    <ImageView
        android:layout_width="21dp"
        android:layout_height="21dp"
        android:layout_gravity="center_vertical"
        android:layout_margin="12dp"
        android:src="@drawable/pngfile"
        />

Imagine that I launch the app on an android device with 1080x1920 dimension and later I launch the app on another device with 1440x2560. What will be the size of this UI? Will these 21dp of width and height adapt to different screen sizes? I mean if the screen size is bigger this xml file will be bigger and if the screen size is smaller it will be smaller adapting to all screen sizes?Or it will have an independent size for all screen dimensions?

Upvotes: 1

Views: 1080

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006539

Imagine that I launch the app on an android device with 1080x1920 dimension

1080x1920 is a resolution, not a dimension.

What will be the size of this UI?

It will be 21dp by 21dp. Since 1 dp is 1/160 of an inch, it will be 21/160 inches = 0.13125 inches on a side.

Will these 21dp of width and height adapt to different screen sizes?

No. dp units adapt for screen density, not resolution.

I mean if the screen size is bigger this xml file will be bigger and if the screen size is smaller it will be smaller adapting to all screen sizes?

No.

Or it will have an independent size for all screen dimensions?

It will have an independent size for all screen resolutions.

Upvotes: 2

Related Questions