android - how to set width of widget programatically in dips -


i'm adding widget layout dynamically. need set widget width 100 through code below :
width = 100; how can convert above given value dps in android

/**  * method converts device specific pixels density independent pixels.  *   * @param px value in px (pixels) unit. need convert db  * @param context context resources , device specific display metrics  * @return float value represent dp equivalent px value  */ public static float convertpixelstodp(float px, context context){     resources resources = context.getresources();     displaymetrics metrics = resources.getdisplaymetrics();     float dp = px / (metrics.densitydpi / 160f);     return dp; } 

credit: converting pixels dp


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -