get Pixels from dps - Android android.graphics

Android examples for android.graphics:Pixel

Description

get Pixels from dps

Demo Code

import android.content.Context;

public class Main {

  public static int getPixels(float dps, Context context) {
    float scale = context.getResources().getDisplayMetrics().density;
    int pixels = (int) (dps * scale + 0.5f);

    return pixels;
  }//from w w w .  ja v  a  2 s.c om

}

Related Tutorials