If i have 96dip on a smaller screen device, it will enlarge to keep the ratio to the large screen device.
Am I right?
That's right.
From the developer guide:
Density-independent pixel (dp)
A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
Related
I read about dp and pixel and calculate dpi and pixel . but i am confused. I want to know if I want to create UI for my app, is better what resolution I select for beginning? I want to use of Photoshop. on design section in Android studio, there are e few devices with their resolutions,for example (480 * 800 hdpi(nexus one)) and so on . but which one is better for first create on photoshop?
I suggest using px for design
Mobile: 360 x 640
Tablet 7inch: 600 x 960
Tablet 9inch: 1024 x 768
References
https://i.stack.imgur.com/rrNoM.png
https://i.stack.imgur.com/ueFa0.png
https://i.stack.imgur.com/CAt1u.png
Use Density-independent pixel (dp) units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
The android documentation says :
A virtual pixel unit that you should use when defining UI layout, to
express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a
160 dpi screen, which is the baseline density assumed by the system
for a "medium" density screen. At runtime, the system transparently
handles any scaling of the dp units, as necessary, based on the actual
density of the screen in use. The conversion of dp units to screen
pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi
screen, 1 dp equals 1.5 physical pixels. You should always use dp
units when defining your application's UI, to ensure proper display of
your UI on screens with different densities.
You can read it here
For correct icon size you should read answer this
I am looking at setting the FontSize of my application based on how big my device is. i.e. If the device is below 8" make the font smaller than the default.
So the device I am using is a Lenovo S8-50 8-Inch Tablet and as you can see in the specifications Screen Size: 8 inches
So looking at some code on Github I see the following:
var d = Resources.System.DisplayMetrics;
this.ScreenHeight = (int)(d.HeightPixels / d.Density);
For this device the number returned is 912 and I can't figure out how this number relates to the device.
So my question is what does this number actually represent?
From the Official documentation:
Density-independent pixel (dp)
A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
This will also be helpful:
Understanding density independence
I have understood the concept of dp and dpi for different layouts and images being used in android. But my doubt (sorry if dumb) is why did android come up with a concept of density pixel, density independent pixel instead of percentages just like in html. It is getting difficult for the developer..
Because of to support multiple screens android introduced this dp and dip concepts
dp or dip
From the Android Documentation for Supporting Multiple Screens:
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160
dpi screen, so one dp is one pixel on a 160 dpi screen.
Use of dp:
Density independence - Your application achieves “density independence” when it preserves the physical size (from the user’s
point of view) of user interface elements when displayed on screens
with different densities. (ie) The image should look the same size
(not enlarged or shrinked) in different types of screens.
Density-independent pixel is a virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position
in a density-independent way.
The density-independent pixel is equivalent to one physical pixel
on a 160 dpi screen, which is the baseline density assumed by the
system for a "medium" density screen. At runtime, the system
transparently handles any scaling of the dp units, as necessary, based
on the actual density of the screen in use. The conversion of dp
units to screen pixels is simple: px = dp * (dpi / 160).
For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels.
You should always use dp units when defining your application's UI,
to ensure proper display of your UI on screens with different
densities.
I am new to android. I read about DP but m still confused. In one definition it says-
dp (density-independent pixels): An abstract unit based on the density of the screen. On a display with 160 dots per inch, 1dp = 1px.
does it mean- 160 dots=1 dp = 1 px (each dot is 1 pixel , right?)
OR 1 dp = 1 dot(pixel) among the 160 dots
Pleas clarify
density-independent pixels is a virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple:
px = dp * (dpi / 160)
For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
For 160 dpi screen 1 dp equals 1 px.
Refer to this blog and this answer.
The android documentation say -
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, the baseline density assumed by the platform (as described later in this document). At run time, the platform transparently handles any scaling of the dp units needed, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: pixels = dps * (density / 160). For example, on 240 dpi screen, 1 dp would equal 1.5 physical pixels. Using dp units to define your application’s UI is highly recommended, as a way of ensuring proper display of your UI on different screens.
you may take a look at the supporting multiple screens. you may also take a look at this question.
What is the formula for converting regular pixels to DIP?
Assuming I have a photoshop document with a design in it that was intended for the Galaxy Tab (for example) which is 600x1024 actual pixels.
What is the ratio between those and the DIP? I'm unclear on how Android translates this.
I want to use DIP (rather than pixels) so that it scales to look "ok" on other devices, but my primary concern is to get it pixel perfect in this resolution and my aim is to measure the position of an element in photoshop and then get an exact translation as to what the DIP needs to be for it to lay out identically on the Tab.
Their formula is somewhere in the docs:
truePixels = DIPs * (device DPI / 160)
Ah, there it is:
The density-independent pixel is
equivalent to one physical pixel on a
160 dpi screen, which is the baseline
density assumed by the system for a
"medium" density screen. At runtime,
the system transparently handles any
scaling of the dp units, as necessary,
based on the actual density of the
screen in use. The conversion of dp
units to screen pixels is simple: px =
dp * (dpi / 160). For example, on a
240 dpi screen, 1 dp equals 1.5
physical pixels. You should always use
dp units when defining your
application's UI, to ensure proper
display of your UI on screens with
different densities.
Taken from here.