convert Pixels To Dp for Context - Android android.content

Android examples for android.content:Context

Description

convert Pixels To Dp for Context

Demo Code

import android.content.Context;

public class Main {

  public static float convertPixelsToDp(float px, Context ctx) {
    return px / (ctx.getResources().getDisplayMetrics().densityDpi / 160f);
  }/*from  w  ww.  j a v a 2s. c  o  m*/

}

Related Tutorials