//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());