public static int pixelsToPt(Context context, int sp) //context可傳入this.getApplicationContext()
{
float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
return (int) (sp*scaledDensity);
}
public float convertDipToPixels(int dips)
{
Resources r = getResources();
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dips, r.getDisplayMetrics());
}
沒有留言:
張貼留言