Android如何在代码中将PX转换成DIP

mac2022-06-30  32

//px转换成dip public int dip2px(Context context, float dipValue){ final float scale = context.getResources().getDisplayMetrics().density; return (int)(dipValue * scale + 0.5f); } 下面是如何调用: a1.setPadding(a1.getPaddingLeft()+this.dip2px(this, 5),a1.getPaddingTop(),a1.getPaddingRight(),a1.getPaddingBottom());

转载于:https://www.cnblogs.com/xiaobuild/archive/2011/10/09/2203453.html

最新回复(0)