2

I am having psd files to develop android layouts. How can I make layout scalable and pixel to pixel as per given psd. I can use ruler to figure out the height and width of object in psd but how can i scale up in dp in Android xml. ?

Any help would be appreciable

  • 1
    Here is a unified guide to understand dp-px-sp converting http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-in-android – Sergii Sep 24 '15 at 21:15
  • what you need to take notice is that dp are device depended and with each other device it will look different even when the dp is the same for them all – Daniel Mendel Sep 24 '15 at 21:20
  • Actually I understand the conversion but How can i apply it? According to you first I need to figure it out the device type (mdpi/xdpi/xhdpi) and then convert the height and width (from psd in pixel) and convert it into device type and apply it in layout –  Sep 24 '15 at 21:21
  • "How can I make layout scalable and pixel to pixel as per given psd." Please don't. It doesn't work that way on Android. On iOS, you can open the application drawer on a iPhone 5 and find 9 icons. And then, you can do the same on an iPad with retina display, and again you'll find 9 icons when you've opened its application drawer. But the UI guidelines for Android are very clear, the layout of a tablet shouldn't be simply the blown up version of a phone's. If you try to do the same thing on Android, your Android users will crucify you in the reviews. – Stephan Branczyk Sep 24 '15 at 22:53
  • @StephanBranczyk What should I do then? –  Sep 24 '15 at 23:09
  • @StephanBranczyk I am also having the same problem. Can you please look at http://stackoverflow.com/questions/32772318/how-to-create-android-layout-matches-pixel-to-pixel-from-psd – Amit Pal Sep 24 '15 at 23:20
  • Follow the UI Android conventions. Keep your layouts flexible. Figure out at what dimensions your layouts may break. Tell your designer that he shouldn't expect a precise rendition of his PSDs. http://developer.android.com/guide/practices/screens_support.html Use relative layouts, or LinearLayouts (but preferably Relative Layouts). Or use ListViews/Gridviews. Use a different layout for tablets vs. phones. Use dps, not pixels. Test your design on a couple different phone/tablets (not all the combinations, just some of the ones that are used by 90% of users according to the google dashboard). – Stephan Branczyk Sep 25 '15 at 00:00
  • See this http://stackoverflow.com/questions/17345115/android-ui-design-supporting-multiple-screens and this http://stackoverflow.com/questions/21787476/design-for-different-screen-sizes-android – Stephan Branczyk Sep 25 '15 at 00:06

1 Answers1

1

Convert pixels back to dp and use it in your xml files.To convert pixels to dp you can do it through code or using some tool like http://androidpixels.net/

Through code you can do it using this:

float ht_px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 
ht, getResources().getDisplayMetrics());
rupesh jain
  • 3,410
  • 1
  • 14
  • 22
  • I don't know that this comment make sense or now but what if I zoom out and zoom in the psd file because in that case you will have different pixel of height and width. what should I suppose to do in this case? –  Sep 24 '15 at 21:23
  • you should take the dimension only when the file is in original size and put it xml..rest all things are taken care by platform – rupesh jain Sep 24 '15 at 21:53
  • I am also having the same problem, So I check the dimension of a button given in psd i.e. `93` pixel. Then I use the tool to convert the value for xxhdpi device i.e. nexus5. The value I got is 33.3dp which is not scalable fit to screen. The value is fitting to screen or given psd is 50dp What should I do? – Amit Pal Sep 24 '15 at 23:07