Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Dimens Value calculation for different values folders

I am giving size in dimen value for some UI components.My UI need to be supported by all devices in portrait mode so I put my dimen files into 16 folders

enter image description here

At first I inserted values in values-normal-xhdpi (as I have the device to test) .So now I have built my dimen file for values-normal-xhdpi folder.Now I am doing entries in values-normal-hdpi by again checking visual effect for normal-hdpi screen.This is really a hectic task I need some formula so that I can evaluate the value of dimens for remaining of folders.

Some of android standards says that drawable image should be in these ratio:

ldpi =0.75

mdpi =1.0

hdpi =1.5

xhdpi =2

but this is not working here as dimen value 100 dp for values-normal-mdpi is not give same effect as value 150 dp gives in values-normal-hdpi

My dimens.xml for values-normal-xhdpi

<resources>
    <!-- this is used in note -->
    <dimen name="text_size_h1">60sp</dimen>
    <dimen name="text_size_h2">50sp</dimen>
    <dimen name="text_size_h3">40sp</dimen>
    <dimen name="text_size_h4">30sp</dimen>
    <dimen name="text_size_h5">24sp</dimen>
    <dimen name="text_size_h6">20sp</dimen>

    <dimen name="text_size_h8">11sp</dimen>
    <dimen name="text_size_h10">10sp</dimen>
    <dimen name="text_size_h12">8sp</dimen>


    <dimen name="extra_mini">2dp</dimen>


    <dimen name="mini">4dp</dimen>
    <dimen name="x_mini">10dp</dimen>
    <dimen name="xx_mini">14dp</dimen>
    <dimen name="xxx_mini">20dp</dimen>

    <dimen name="mid">30dp</dimen>
    <dimen name="x_mid">40dp</dimen>
    <dimen name="xx_mid">50dp</dimen>
    <dimen name="xxx_mid">60dp</dimen>

    <dimen name="max">70dp</dimen>
    <dimen name="x_max">62dp</dimen>
    <dimen name="xx_max">90dp</dimen>
    <dimen name="xxx_max">100dp</dimen>

    <dimen name="supper">110dp</dimen>
    <dimen name="x_supper">120dp</dimen>
    <dimen name="xx_supper">130dp</dimen>
    <dimen name="xxx_supper">140dp</dimen>

    <dimen name="xxxxxx_supper">180dp</dimen>

    <dimen name="image_width">628dp</dimen>
    <dimen name="image_height">270dp</dimen>

</resources> 
like image 712
Vibhor Bhardwaj Avatar asked Apr 30 '14 14:04

Vibhor Bhardwaj


1 Answers

"dp" are Density Independent Pixels. 100dp means 100px in mdpi, 150px in hdpi, 200px in xhdpi, &c.

This means that you do not need to specify values for each density variant if you always use dp (which is a good idea), they are converted automatically to pixels values for each one.

See http://developer.android.com/guide/practices/screens_support.html#terms

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.

like image 183
matiash Avatar answered Oct 13 '22 01:10

matiash