Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

最后面算px和dp转换的dp2px方法里面返回有个0.5f什么意思。。 #3

Closed
516457377 opened this issue Aug 19, 2016 · 4 comments

Comments

@516457377
Copy link

private int dp2px(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
感觉没多大用啊

@516457377
Copy link
Author

感谢作者,我用了两天,,终于学会了自定义动画效果了

@SheepYang1993
Copy link

@516457377 四舍五入保证精度

@516457377
Copy link
Author

@SheepYang1993 没太懂。。0.5个像素。。怎么个保精度。。

@JeasonWong
Copy link
Owner

@516457377

http://developer.android.com/guide/practices/screens_support.html

Then add 0.5f to round the figure up to the nearest whole number, when converting to an integer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants