Skip to content

Instantly share code, notes, and snippets.

@brucetoo
Created August 19, 2015 12:19
Show Gist options
  • Select an option

  • Save brucetoo/3179a1ed23e9942068be to your computer and use it in GitHub Desktop.

Select an option

Save brucetoo/3179a1ed23e9942068be to your computer and use it in GitHub Desktop.
不用Context 将sp和dp转换成px
private int dp2px(float dpVal) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
dpVal, getResources().getDisplayMetrics());
}
private int sp2px(float dpVal) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
dpVal, getResources().getDisplayMetrics());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment