Android Tablet "dp" difference - android

I would like to create a adaptive UI for both mobile and tablet devices. I would like to know for example for mobile devices if I give android:textsize="2dp then how much I should give for tablet devices. I know I should give them in values-w820dp and appropriate folder but how to calculate the difference of this dp. I couldn't find any resource for this. Help me out.

(1) For most text, it's best to size it in sp units so it scales automatically relative to the user's text-size preference. Folks with lesser vision can pick larger text and then be able to read your app without eyestrain.
(2) If you need some text to appear in a fixed size, e.g. a big headline, then use dp units so it scales automatically relative to the screen's pixel density. (Pixel density is independent of the overall screen size. It's a high vs. low density thing, not a phone vs. tablet thing.)
But don't use size 2dp! That'd be unreadably tiny -- the height of 2 physical pixels of a 160 dpi screen.
(3) If you need some text that uses approximately a fixed proportion of the screen size, then it makes sense to either define screen-size-dependent parameters, e.g. in values-w820dp, or to size it in code.
(4) If you need some text in a fixed number of pixels tall even when the pixels are really tiny, e.g. to draw into a raster image, then use px units.
See Supporting Multiple Screens - best practices.

There are no strict rules here. You can have android:textsize="2dp on your tablet as well if you wish so. You can have a look at the following android developer page which tells how to support tablets and contains chapter called: 5. Adjust Font Sizes and Touch Targets

Related

Are there any truly display independent units for placing things on android canvas/screen?

I'm developing a watch face for wear os. I was trying to figure out why the layout is messed up on different screen sizes and resolutions - I was using "dp" for all dimensions so I thought it will be "density independent", yes?
I made few emulators with different dpi and sizes and could not figure out why bigger change id dpi makes my layout look good again, but smaller changes introduce offset. I found out that:
One note about dp/sp that isn't totally obvious: The scaling that occurs for these depends not on the devices real density (dpi) but on which "bucket" of densities it falls into: available buckets are: 120,160,240,320. (...)
Note that pt should give you equivalent results as dp
So are there any truly display independent(proportional to screen) units I can use to position my elements?

Best unit for text and dimensions in Android

I've been using dp for dimensions and sp for text size for 3 years now, ever since I've started developing apps for Android.
But recently, I've been joined with a couple people that don't believe in dp and sp saying "it doesn't show the same on all devices".
The method they've used is:
When setting the text size, you don't use 24 sp nor 24 dp, you set it as 24% of the screen width or height in pixels. in this way, the text is always the same size in pixels on all devices (including tablets).
How correct/valid is this method? What is the professional way to design? What is the opinion of a professional Android designer to this method?
Don't know how good % can replace dp, but don't use it as a text size.
sp is great because users can resize it by changing their preferred text size in the device settings. Don't take away this possiblity just because it makes your design easier for you.
Accessibility > Design
See this guide for reference: Support different pixel densities
When defining text sizes, however, you should instead use scalable pixels (sp) as your units (but never use sp for layout sizes). The sp unit is the same size as dp, by default, but it resizes based on the user's preferred text size.
Best unit for text is sp and for dimensions best unit is dp.
That is given perfect result of in which you want.
In most of developer use this unit for text and dimensions.
I try for your % but that is not work in my app.
dp stands for density independent pixels. Its goal is, to define a more or less physical dimension. E.g. 48dp are about the size if a finger tip, and that's why tappable icons (e.g. on ActionBar) should have that size.
So for UIs you should always use dp (and sp for texts). It also has the advantage, that you can show more data on a larger screen (e.g. more items in a list are visible etc.).
If you're using % of the screen size, you are doing the exact opposite. On a small device 24% it will be small (physically speaking) on a large tablet it will be large.
Using % might make sense if you're developing a game for example and you want the same image shown on every device, large or small.
DP/SP Does not claim to be the same on all screen sizes but about the same size across screen densities. The reason it is only about the same size is that density is broken up into categories (e.g. mdpi, hdpi, xhdpi...).
You don't want the text to be relative to the screen size because then the text will be really small for devices that have a small screen and really large for devices that have a large screen. Instead you want the font size to be comfortable to read and about the same size on large or small screen. The large screens will just have the advantage of more text on the screen at a time.
In addition as other users have mentioned sp (and apparently now dp) can be scaled based upon user preferences which is really helpful for people with poor eyesight.

Does `wrap_content` works the same way as Density Pixels?

I have read Android guidelines regarding different screen sizes, but still I have some considerations.
Client has given me an image from PSD file which has certain resolution that fits
1080 X 1920. I just use wrap_content, and it perfectly fits the part
of screen.
I am not using DP to define its width-height, If i was using DP it would have
adjusted image according to screen sizes.
My questions are,
Does wrap_content works the same way as Density Pixels?
Is it also responsive, and changes the image width-height according
to different screens?
If not, then Is it necessary to use DP to support different screen
sizes ?
Thanks
The setting wrap_content tells your view to size itself to the dimensions required by its content. In the case of your test, your image is 1080x1920 and your device's screen resolution is likely 1080x1920 as well, hence the perfect fit. Since you set the width and height to wrap_content, Android is simply trying to use as much screen space as it needs to correctly display the amount of content it was supplied. In this case, since the available screen space matches the size of the content, it just fits perfectly.
But what if the device screen isn't 1080x1920? In that case, Android will only use as much space as it can, but still attempt to fit the image inside the bounds of the available screen space. In other words, the system will appropriately scale the image down to get it in the container you have provided for it. But this can lead to awkward fits if the aspect ratio isn't the same as the image. For instance, see this screenshot below:
This image is 1920x1080, but notice that it doesn't quite fit. That's because this nexus 7 screen is 1824x1200 when viewed in landscape. Additionally, the toolbar at the top of the screen is eating up available screenspace, making my viewable area even smaller and more awkwardly shaped. So while the system would love this image to extend all the way to the left and right borders, it can't, because then that would mean the height would be bigger than the viewable space. Since I used wrap_content to display this image, the system is using as much vertical space as it can, and the result is that the image doesn't quite fit the horizontal space.
So to more directly address your questions, yes wrap_content is a relative size setting that will make it easier to get a consistent look across multiple screen sizes, similar to using dp. But realize that there are hundreds, if not thousands of available Android devices on the market, and they all have varying screen sizes and densities. So your drawables may not always appear the way you want them on every device.
The way to overcome this is to supply multiple versions of your assets and provide alternate layout files for different screen sizes and densities. Once you do that, all you can do is test, test, and test some more. Use emulators for weird screen densities or devices you don't own, just to make sure you're getting the look you want. In the case of your 1920x1080 image, it looks great on that one device, but how will it fit a large tablet or a tiny handset that is smaller than the resolution of the image? These are situations you must account for in your design.
I suggest you read these resources, as they are hugely helpful in learning how to deal with issues resulting from varying screen sizes and densities:
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/training/multiscreen/screensizes.html

Supporting Multiple Screens in Android

I have developed an android app and its working fine in my mobile of resolution 240*320.But if I install in another mobile some like 240*400,480*800, etc all the view components are changing according to the screen resolution.
I also created a sub folders under the res like layout-small,layout-large,layout-xlarge this procedure is also working according to the screen resolution the xml files are been read by particular folder.But this is not working on a 240*400,240*432,etc.., these type of screen resolutions are not supporting by the above procedure
What should i do for achieving all the view components to be look same for all screen sizes.
Thank you
This stuff is hard. You may have read the documentation, but you haven't understood it.
Basically, you have to distinguish two important things.
Layouts (XML) are determined by the dp size of the device. Forget about 'resolution' and just think about device independent pixels (dp). The dp size of a device is roughly equal to its size in inches, if it had 160 dots per inch. So a 10" tablet is about 8"x160=1280 dp long, while a 4" phone is about 3"x160=480 dp long. Approximately.
Drawables (PNG and JPG) are determined by the pixel resolution of the device. To produce the identical icon on a device that is 320 dpi and for one that is 160 dpi you need twice as many pixels. A 64x64 icon on the first is only 32x32 on the second.
So you need to produce a range of XML files (layout or dimen) that scale according to the desired dp size and put them in folders with names like sw600dp (shortest width 600 dp) and sw320dp. (Search SO or the web for sw600dp and you'll find lots to read).
And you need to produce a range of PNG or JPG files that scale according to the pixel resolution and put them in folders with names like mdpi and hdpi (search for that too).
Simple enough, but hard to do well in practice. We can only hope that eventually Android will fix this mess but for now this is what we have.
First off, stop using the term resolution. That term is ambiguous.
In Android, one could easily have a phone with a small screen with very high pixel density and a large tablet screen with very low pixel density, and the so-called resulting resolution on both devices could still end up being equal.
i have read that many times and implemented according to that but read
my question properly. – user3851899 3 hours ago
I'm sorry, but believe us, we've parsed your question very thoroughly.
http://developer.android.com/guide/practices/screens_support.html
You've mentioned the term "resolution" five times and yet in the document you've read many times, below is the only part where resolution is even mentioned, and even then, it's to tell us that you should "not directly work with resolution".
Resolution
The total number of physical pixels on a screen. When adding support for multiple screens, applications do not work
directly with resolution; applications should be concerned only with
screen size and density, as specified by the generalized size and
density groups.
Furthermore, can you count the term density is mentioned in that document. It's mentioned 171 times! The fact is, you've missed the main key take away concept from that document.
The term resolution is not very useful for Android development. The concept of size is important for a large background image taking the entire width or the entire height of the screen and it's important for layout issues that take into account the entire height of the screen or the entire width of the screen, but it's not very important otherwise. And what's really important for developing on multiple screens (aside from the scaling font size) is really the density of the screen.
So I implore you, please read that document again. Hopefully, you'll begin to understand it, now that I've reset some of your assumptions.

Image compatibility in iphone and android

I developed UI for iphone apps and now want to use the same UI in Android apps. I read that Android use dip for image resolution and i also read that 1 dip=1.5 pixel.I simply multiply the image size by 1.5px. Now the problem is that the image is blur and not as clear as in iphone apps.So will some body suggest me how should i make a design so that it could be used in iphone and android.
dip is not simply the same as 1.5 pixels. A dip is a density independent pixel, and allows you to size items in a way so that they will look similar on displays with different pixel densities. When performing the layout Android scales the dip value depending on the pixel density of the device.
However, dip works best when sizing items which scale well, like the Android widgets. If you have an image you may want to always display it "actual size" so the image doesn't get scaled and become blurry - i.e. size it in pixels and not dip. So what you may have to do is supply a number of versions of each image so that you have a version that looks good for the screen densities on all the devices you choose to support. This is turn may mean producing a number of different layouts, depending on how you use your images.
I think it is not a big problem.You just copy your all images from drawable-hdip from drawabel-mdpi.It will work fine.

Categories

Resources