Android: what is the difference between resolution and density?
Asked Answered
L

6

24

According to Android definitions, I've found that:

  • Resolution: The total number of physical pixels on a screen

  • Density: Based on the screen resolution, the spread of pixels across the physical width and height of the screen.

How can I understand better the differences between the two definitions?

Loch answered 1/4, 2011 at 21:6 Comment(3)
Here is a Wikipedia article on screen density: en.wikipedia.org/wiki/Pixel_densityChauffer
think of density as pixels-per-inchCompanionway
Screen resolution: The number of pixels a screen contains both horizontal and vertical, such as 320x480. Screen density: Is how close together they are, usually expressed in Dots Per Inch (DPI).Bowerman
H
34

Resolution is about how many pixels you can show on screen.

Density is based on your device real size, if it's small and has a higher resolution, than the density is high cause you show more pixels in less physical space.

Hat answered 1/4, 2011 at 21:8 Comment(0)
A
44

Resolution is a measure of how many pixels a display can show at a time eg. 640x480. Density is a measure of how big each pixel is in actual units. This relates heavily to screen size eg. 640x480 on a 15' display.

When comparing one device's resolution to another, it's a straight-forward comparison: the higher the resolution, the more information you can display at a time. When comparing density: the higher the density the sharper the display will appear.

If you have high resolution and low density, then your screen will be very large. On the other hand, low resolution and high density will result in a very small screen.

Augment answered 1/4, 2011 at 21:10 Comment(1)
@committedandroider by information he means more pixels can be shown, as resolution directly relates to number of physical pixels a device can show.Plectognath
H
34

Resolution is about how many pixels you can show on screen.

Density is based on your device real size, if it's small and has a higher resolution, than the density is high cause you show more pixels in less physical space.

Hat answered 1/4, 2011 at 21:8 Comment(0)
U
9

Basically:

  1. Resolution concerns an absolute number of pixels. (check out wikipedia Image Resolution)
  2. Density (aka Pixels per inch - PPI) concerns a relative number of pixels per inch. (check out the wikipedia Pixel Density)

Take care, Beco

Unlovely answered 4/4, 2011 at 19:21 Comment(0)
A
2

Best Practices


The objective of supporting multiple screens is to create an application that can function properly and look good on any of the generalized screen configurations supported by Android. The previous sections of this document provide information about how Android adapts your application to screen configurations and how you can customize the look of your application on different screen configurations. This section provides some additional tips and an overview of techniques that help ensure that your application scales properly for different screen configurations.

Here is a quick checklist about how you can ensure that your application displays properly on different screens: 1.Use wrap_content, fill_parent, or dp units when specifying dimensions in an XML layout file 2.Do not use hard coded pixel values in your application code 3.Do not use AbsoluteLayout (it's deprecated) 4.Supply alternative bitmap drawables for different screen densities

The following sections provide more details.

  1. Use wrap_content, fill_parent, or the dp unit for layout dimensions

When defining the android:layout_width and android:layout_height for views in an XML layout file, using "wrap_content", "fill_parent" or dp units guarantees that the view is given an appropriate size on the current device screen.

For instance, a view with a layout_width="100dp" measures 100 pixels wide on medium-density screen and the system scales it up to 150 pixels wide on high-density screen, so that the view occupies approximately the same physical space on the screen.

Similarly, you should prefer the sp (scale-independent pixel) to define text sizes. The sp scale factor depends on a user setting and the system scales the size the same as it does for dp.

  1. Do not use hard-coded pixel values in your application code

For performance reasons and to keep the code simpler, the Android system uses pixels as the standard unit for expressing dimension or coordinate values. That means that the dimensions of a view are always expressed in the code using pixels, but always based on the current screen density. For instance, if myView.getWidth() returns 10, the view is 10 pixels wide on the current screen, but on a device with a higher density screen, the value returned might be 15. If you use pixel values in your application code to work with bitmaps that are not pre-scaled for the current screen density, you might need to scale the pixel values that you use in your code to match the un-scaled bitmap source.

If your application manipulates bitmaps or deals with pixel values at runtime, see the section below about Additional Density Considerations.

  1. Do not use AbsoluteLayout

Unlike the other layouts widgets, AbsoluteLayout enforces the use of fixed positions to lay out its child views, which can easily lead to user interfaces that do not work well on different displays. Because of this, AbsoluteLayout was deprecated in Android 1.5 (API Level 3).

You should instead use RelativeLayout, which uses relative positioning to lay out its child views. For instance, you can specify that a button widget should appear "to the right of" a text widget.

  1. Use size and density-specific resources

Although the system scales your layout and drawable resources based on the current screen configuration, you may want to make adjustments to the UI on different screen sizes and provide bitmap drawables that are optimized for different densities. This essentially reiterates the information from earlier in this document.

If you need to control exactly how your application will look on various screen configurations, adjust your layouts and bitmap drawables in configuration-specific resource directories. For example, consider an icon that you want to display on medium and high density screens. Simply create your icon at two different sizes (for instance 100x100 for medium density and 150x150 for high density) and put the two variations in the appropriate directories, using the proper qualifiers: res/drawable-mdpi/icon.png //for medium-density screensres/drawable-hdpi/icon.png //for high-density screens

Authentic answered 25/11, 2013 at 6:19 Comment(1)
or follow the link developer.android.com/guide/practices/…Authentic
L
2

Resolution => Cp * Rp (Number of PIXEL in COLUMN & Number of PIXEL in RAW)

Density => Np / 1 Inch (Number of PIXEL per inch)

Lundin answered 19/2, 2015 at 9:40 Comment(0)
F
2

Resolution is the number of pixels on a device found in each dimension (width × height) that can be displayed on the screen.

For example, a device with the resolution of “1024 × 768” has a 1024-pixel width and a 768-pixel height.

Pixel Density is usually measured in PPI (Pixels Per Inch), which refers to the number of pixels present per inch on the display. A higher pixel density per inch allows for more sharpness and clarity when using the device.

For example, If a device screen is called "100 PPI" then it means that it has 100 psychical pixels per inch.

Reference

Forereach answered 1/4, 2020 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.