Avoid using "px" as units; use "dp" instead
2012-06-28 15:33
615 查看
今天在写程序的时候,使用px设置组件宽度,弹出Avoid using "px" as units; use "dp" instead的提示,并且编译不通过
dp是可以根据屏幕大小变化的,而px就不行,主要是Android不主张再使用固定的长度单位了,如果想把dp转换成px值,
那么使用如下的代码
dp是可以根据屏幕大小变化的,而px就不行,主要是Android不主张再使用固定的长度单位了,如果想把dp转换成px值,
那么使用如下的代码
public static int dpToPixels(Context context, float dp) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dp * scale + 0.5f); }
相关文章推荐
- Avoid using "px" as units; use "dp" instead
- Avoid using "px" as units; use "dp" instead
- 关于iview中[Vue warn]: Avoid using non-primitive value as key, use string/number value instead.影响性能的问题
- 解决element-ui upload组件报错 Avoid using non-primitive value as key, use string/number value instead
- [常见错误 及 解决方案系列]USE " cc.exports.* = value " INSTEAD OF SET GLOBAL VARIABLE"
- [常见错误 及 解决方案系列]USE " cc.exports.* = value " INSTEAD OF SET GLOBAL VARIABLE"
- error C2275: "xxx"illegal use of this type as an expression
- Freemaker:you just want "true"/"false" result as you are generting computer-language output, use "?c
- Avoid to use "IN", "NOT IN" in SQL statement, try to use "LEFT JOIN" instead.
- ReactNative.createElement is deprecated. Use React.createElement from the "react" package instead.
- 解决Package illuminate/html is abandoned, you should avoid using it. Use laravelcollective/html instead.问题
- 官方论坛的帖子 How about use "armeabi-v7a" as default ABI on Android for template? ABI 是啥?
- 关于http客户端常见错误"警告:Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
- Do not hardcode "/data/"; use Context.getFilesDir().getPath() instead 解决方法
- warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _
- error: #error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."解决
- 'filename.h' file not found with <angled> include, use "quotes" instead. 问题详解
- #("The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name:")
- Avoid Using The “system("pause")” !
- 关于http客户端常见错误"警告:Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is rec"