Avoid using "px" as units; use "dp" instead
来源:互联网 发布:梦里花落知多少 阅读 编辑:程序博客网 时间:2024/05/17 01:35
今天在写程序的时候,使用px设置组件宽度,弹出Avoid using "px" as units; use "dp" instead的提示,并且编译不通过
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
- Avoid using "px" as units; use "dp" instead
- 问题归纳(1) Avoid using "px" as units; use "dp" instead
- 关于iview中[Vue warn]: Avoid using non-primitive value as key, use string/number value instead.影响性能的问题
- storm杂谈之Why use netty as transport instead of zeromq
- Why does Quora use MySQL as the data store instead of NoSQLs such as Cassandra, MongoDB, CouchDB etc?
- Why does Quora use MySQL as the data store instead of NoSQLs such as Cassandra, MongoDB, or CouchDB?
- Using C-style cast. Use reinterpret_cast<int*>(…) instead [readability/casting] [4]
- 【收藏】Avoid switch! Use enum!
- Use a layout_height of 0dip instead of 700dp for better performance
- Use a layout_height of 0dp instead of match_parent for better performance问题说明
- How many hidden units should I use?
- Using Handler to Avoid ANR
- Avoid Using The “system("pause")” !
- use supervisor instead of nohup
- warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _
- Understanding and Using rem Units in CSS
- 黑马程序员--java学习之javaBean与注解
- AJAX - 向服务器发送请求
- there is a problem parsing the package
- 【LaTeX】文章中插入Visio及Matlab矢量图
- ExtJS 2.0官方实例目录
- Avoid using "px" as units; use "dp" instead
- 敏捷模型驱动开发(AMDD):攀登敏捷软件开发的关键
- <shlwapi.h> StrCat(a1,a2);
- 创建QTreeWidget组件
- “谷歌百度一键搜索” -- 最方便的Chrome搜索插件
- mongo数据库分片技术的实现
- String.Empty,NULL和""的区别
- vi 常用命令-设置vi的tab宽度为4
- linux cpu信息查看