屏幕适配
2015-11-11 09:45
246 查看
关于屏幕布局适配建议
1、不要使用绝对布局2、尽量使用match_parent 而不是fill_parent 。
3、能够使用权重的地方尽量使用权重(android:layout_weight)
4、如果是纯色背景,尽量使用android的shape 自定义。
5、如果需要在特定分辨率下适配,可以在res目录上新建layout-HxW.xml的文件夹。比如要适配1080*1800的屏幕(魅族MX3采用此分辨率)则新建layout-1800x1080.xml的文件夹,然后在下面定义布局。Android系统会优先查找分辨率相同的布局,如果不存在则换使用默认的layout下的布局。
代码实现
/** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } /** * 根据手机的分辨率从 px(像素) 的单位 转成为 dp */ public static int px2dip(Context context, float pxValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); }
相关文章推荐
- 《IT蓝豹》PlayNewsStandDemo资讯类新闻客户端框架
- Mac安装 RVM
- QML Item详解
- angularJS的过滤器详解
- 细说MVC框架的几大困惑:
- 存储过程创建表
- 用google mock模拟C++对象
- ngrok国内服务器
- HDU 1045——Fire Net——————【最大匹配、构图、邻接矩阵做法】
- Intent Action列表
- The 60/60 Rule
- Myeclipse字体设置
- 为什么C++中声明和定义要分开写
- How Do You Define “Finished”?
- yum源的安装配置
- 在 Docker Machine 中使用 Mirror 服务
- Android定位功能(二)
- linux命令:grep
- Keep Your Perspective
- 博客开张了!