Created
August 19, 2015 12:19
-
-
Save brucetoo/3179a1ed23e9942068be to your computer and use it in GitHub Desktop.
不用Context 将sp和dp转换成px
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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