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

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -