Converting Density Independent Pixels (dp) to Pixels (px) in Android

Sometimes we need to convert density independent pixels(dip/dp) to pixels to set view properties like width or height. Here how it is done using Java.

    Resources r = getResources();
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 300,       r.getDisplayMetrics());
    myEditText.setWidth(px);

Comments

Popular posts from this blog

Offers on Friday, April 24, 2020

Fatal: LoadModule: error loading module 'mod_sql_mysql.c'