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
Post a Comment