I'd like to ask about one of the hardest thing for me (as a programmer) in android. As I make software mostly without designer (to be honest - totally without a designer) I can't figure out the following:
When I draw a png I use px (not dp) as image width.
I drew a button image with the following sizes:
hdpi: 318x45
mdpi: 212x30
(6 to 4 ratio)
and I would like my button be 80% width of Galaxy s2 which is
Screen Size in Pixels: 480 Pixel x 800 Pixel Screen Size in dp: 352dp
x 587dp
But also I would like to have the same width (80%) for hdpi 10' tablet. Is it possible or I'm missing something?
And is it possible to make 80% but not more than XXX pixel width?
You just need to provide different size images for different screen sizes and densities. When you think about it there's only a few different formats you need to worry about. You will then just create an "80%" size image for each of those formats, place them in the seperate drawable folders, and use them accordingly.
The android docs on supporting multiplce screen size and providing alternative resources are actually pretty comprehensive on how to do this.
Otherwise I'm sorry you don't have a designer. My tip - make your icons originally in Adobe Illustrator if you have it that way you can easily scale them to whatever size you need. As vector images they won't lose quality so you can change the size all you want. When you're ready, just export for web and devices at the size break points and you should be fine.
You have to use the android:layout_weight attribute.
Details outlined in a similar question here
Related
I have the following predicament:
a) I have a designer who designs in photoshop and always uses 72dpi
b) I have developers who get his images and need them to be crisp and sharp for multiple android devices (larger/smaller in size, different dpis)
c) I don't want to confuse the designer with points, dps, etc. I want him to continue using what he knows: 72dpi canvas, all sizes to be specified in pixels
I've read many,many,many threads and links and tutorials and am confused.
Here is what I plan to do:
a) I plan to ask him to design screens using a 720px * 1280px screen. This is the resolution of a Samsung S3
b) I plan to ask him to specify all sizes of items inside reference screen, as well as their distance from phone boundaries in pixels too (I don't want to confuse him)
c) What the developers plan to then do, is take his assets and his reference screens, look at the sizes, and convert to dps in the android layout by basically adding applicable multipliers
d) What the designer also needs to do is resize images in his reference screen for ldpi, mdpi, xhdpi and xxhdpi, which my developers will move to the correct folders so they are picked up at runtime by Android depending on which devices they are testing on
e) NOTE: We plan to have the same layout for all sizes of phones - no different layouts, so assume that the design this person is creating will show well on all sizes
Questions:
1) The designer needs to know with this set up (72dpi PS screen,720x1280), when he is asked to resize images for different dpi buckets, what should he consider his reference screen as? MDPI or XHDPI as he will have to scale his images accordingly when generating them for the developer
2) I want to keep this simple for him. I don't want him to get confused on dpis. So I plan to tell him that forget about dpis when creating your photoshop reference screens -- just design for a 720x1280 screen # the usual 72dpi. Our developers will convert all distances to dps on their side. Any issues with this?
3) I also need to tell my developers how to convert his pixel distances to dps, so I need to tell him what they should treat this 720x1280 72dpi screen as. Is it MDPI or XHDPI?
Thanks
Questions: 1)
Designer needs to design the artwork with XHDPI resolution i.e 720x1280 px
and he need to down scale it with the ratio of
1 or 100% for XHDPI //baseline for designers
0.75 or 75% for HDPI
0.50 or 50% for MDPI
Developer no need to care anything about the artwork sizes or re-sizing them.
Question 2)
You might be confused about what PPI (pixels per inch) to set your deliverables at. Just leave them at the standard 72 PPI, and scale the images accordingly.
// check this Link
Question 3)
Ask your Developer to start design for MDPI first
1 for MDPI //baseline for developers
1.5 for HDPI
2 for XHDPI
use this link for dp calculator
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
Ref here:
Maybe this guide could help you a bit
http://grahamtodman.co.uk/blog/2013/02/how-to-design-android-apps-in-photoshop-what-the-frak-is-a-dp/
This question already has answers here:
Android splash screen image sizes to fit all devices
(11 answers)
Closed 9 years ago.
I'm not new to Android app development. I have already created few apps with very simple UI where I didn't have to worry about screen resolution / dpi / dp... But today I have to create a more advanced Android app with a custom UI design (very "graphic").
I want to implement a splash screen (with an image in full screen). It's difficult and tedious because with Android we have to deal with a lot of resolutions and densities.
My problem
I have no idea what size to put in every drawable folder (ldpi, mdpi, hdpi and xhdpi).
What sizes (in pixels) should i create so the splash displays nice on all screens? Concretely, what files I need to create?
Few remarks
I know there are many other topics on StackOverflow (here, here or here) about Android splash screen / resolution issues. But none of these, in my opinion, gives a understandable / clear answer (I mean, with px).
I have read "Supporting Multiple Screens"
I'm aware of ratio between the densities:
ldpi (0.75x)
mdpi (baseline)
hdpi (1.5x)
xhdpi (2.0x)
xxhdpi (2.5x)
I'm aware of the 9-path image solution but it's not applicable for what I want (a full screen picture).
Tool like this one is helpful to converting dp in px
I have decompressed many APK files to see how these applications deals with splash screen images. None use the same size, it's confusing!
I do not need landscape splash screen.
With a 800x1280px PNG file (in xhdpi) it OK on my Nexus 4 emulator but verticaly stretched on Galaxy S4 emulator.
Like you already pointed out, the case you want to use as your reference frame is mdpi device. You need to make sure that you're happy with how your splash screen looks on mdpi device, and the Android will automatically re-scale your drawables for you, as long as you use .9.png (9-patch image) format and that the device has same aspect ratio.
For more information on 9-patch format, click here.
There is no single aspect for android screen, so there is no perfect solution for showing splash screen. You just need to put your image into some layout and display it as separate activity. Take a look for ImageView and scale property:
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
There is no universal solution for all cases, but try something like that:
put RelativeLayout as base layout, set match_parent for both height and width
put ImageView at center of it, set match_parent for width, wrap_content for height, try scale mode for getting satisfying result.
You can set background drawable for the base layout to fill up margins with some plain color or gradient.
Once you get the correct scalling try how it looks on smaller screens supply other resolutions to avoid excessive downsampling.
What is the applications screen size without the status bar and softkeys(in some phones)?
Like for Example i know:
320X480 trimmed down to 320X455 which is the basesize.
but what about others , i have done many calculations and a lot of searches online to figure out a defined size for other screen but i seems can't, Also While applying the formula *.75 ldpi, *1.5 hdpi, *2.25 xhdpi to get other screen, it doesn't add up.
Like 320X480 is mdpi to get the hdpi do *1.5 and you will get 480X720 which is not the situation for devices out their ! and using this method my application images where stretched, this method is according to the Google documentation, i'm confused as hell.
I have tried to et sizes using the emulator also it was very different! for height.
So if the problem is with height only, i'm thinking creating background as patterns and then work only on the width of the screen size and re-size every other elements to screen width only like 240px, 320px, 480px, 720px and also consider the size of them to fit minimum height.
I believe it's not possible to define a height for android which will go like generic because of the variety of android devices.
So what do you think about this approach to use background as pattern and forget about every device on earth height ?
you can use tile pattern, create a small texture and then make it tileable drawable in xml, so it will be tiled across screen, or the second might be using 9-patch images, in that way you can select which area of the image scale and which area to not scale, so they will be scaled according to that way.
Sorry but i cant understand how i can draw a right picture for the right android phone size.
I readed the android documentation, and they say for i just think in screen size and density and not in resolution, so what size should have my picture?
For example,if i have a phone with size 1000x400(stupid example),and want a button(40x40) that will be in middle,what size should i do?? 40x40?? But in documention they say for dont look for resolution :\
Im confuse...
ps: The documention link Android multiple screens
Basically you'll have to realize that although resolution, screen size and screen density are separate attributes, they are still somewhat related. If your button is 40x40 as you mentioned, and that's the size you find looks good in the center on a hdpi(high density) device, you will have to scale it so that it fits accordingly on mdpi(medium density) and xhdpi(extra high density) devices. What I like to do is use PhotoShop or another graphical editor and resize my assets so that they fit on whatever density devices I'm trying to target. I make sure to always use *WRAP_CONTENT* for my height and width attributes and never fixed values.
Also, if you do not include these scaled alternatives in your res/drawable folders..you're basically saying that you're relying on the system to scale them for you, which can be a gamble. So I always go with resizing my assets so that I include a version for all densities. The link you posed explains everything pretty well
I've got a final app design made i Photoshop where everything is measured in PX.
Now I realize that Android apps are using DP for font-sizes and other things.
Is there any way I can convert PX to DP ?
On a more practical note, you have a few choices in increasing work and fidelty:
Have your resources scaled for 160 dots per inch, put them in your res/drawable directory, and let the OS scale them to look right on the device.
Make two copies of your resources: one at 160 dots per inch in your res/drawable and one at 240 dots per inch in your res/drawable-hdpi directory. Let the OS scale for the exact device starting from a pretty close number.
Decide that you don't want any scaling and have raw pixels, so put your assets in the res/drawable-nodpi directory. This means that at 320x480 (pixel) graphic might be 2 inches by 3 inches on one phone but only 1 1/3 inches by 2 inches on another screen.
Specify the exact scaling strategy for your work, using the draw9patch tool. This can be very useful for keeping the corners of boxes from getting the "jaggies" from scaling and for making full screen graphics cope with different aspect ratios.
Make separate graphics for every device you care about and fall back on scalable graphics for the rest. You will need to outrun zealots waving style guides trying to convince you not to do it this way.
Oh, and as a gotcha, specify sp for your fonts, instead of dp or pt. A 10 point font would be a 22 sp font [ =10 * (160/72) or = number of points times 2.222]. sp units scale with user preferences for small, medium, or large fonts.
From this list of the dimension units supported by Android, here's a description of DP:
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. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
This means that the "conversion" between pixels and DP will not be consistent -- on some devices, the ratio might be 1DP = 160px, but it could theoretically be anything. This is all well and good when you're setting the width of a button to, say, 100dp (since it will get rendered dynamically), but it presents a problem when you have images which must have a fixed size.
Read this page on "Supporting Multiple Screens" -- Android has something called resource directory qualifiers, which let you create size- and density-specific versions of your image resources. For example, for low-density screens, you could create a smaller version of your image and place it in the drawable-ldpi directory (or drawable-hdpi for high-density screens).
tl;dr You can't practically "convert from PX to DP" (since the ratio is not fixed), but you can create multiple versions of your images and tell Android which to use with resource directory qualifiers.
A pixel is PX and the DP or DIP are device independent pixels. I don't think that you need to convert these. But you can use scalable 9patch images using the draw9patch tool from the android tools.
I have same issue but now got the Solution.
Why you not use the online convertor to see which dp or px you have to for different resolution of android device ??
See this link: this link which helps me a lot and also helps you.
Enjoy coding.
This is a online DP/PX Converter tools: http://labs.rampinteractive.co.uk/android_dp_px_calculator/