尺寸工具箱DimenUtils
2015-10-13 10:42
344 查看
/* * Copyright (C) 2013 Peng fei Pan <sky@xiaopan.me> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.xiaopan.android.content.res; import android.content.Context; /** * 尺寸工具箱,提供与Android尺寸相关的工具方法 */ public class DimenUtils { /** * dp单位转换为px * @param context 上下文,需要通过上下文获取到当前屏幕的像素密度 * @param dpValue dp值 * @return px值 */ public static int dp2px(Context context, float dpValue){ return (int)(dpValue * (context.getResources().getDisplayMetrics().density) + 0.5f); } /** * px单位转换为dp * @param context 上下文,需要通过上下文获取到当前屏幕的像素密度 * @param pxValue px值 * @return dp值 */ public static int px2dp(Context context, float pxValue){ return (int)(pxValue / (context.getResources().getDisplayMetrics().density) + 0.5f); } }
相关文章推荐
- java判断是否是周末
- GC overhead limit exceeded : Spark
- 路径说明
- dedecms文件目录结构
- 利用GitHook构建持续交付和部署
- Android开发总结笔记 Date&Time(时间日期相关组件) 1-1-16
- 游戏服务器端开发要点
- 这些git技能够你用一年了
- 读取数据从Uri
- 广播工具箱
- Activity
- c#datagrid的每行的单击事件
- 虚拟引擎
- Mysql 数据库之常用命令[更新中...]
- 如何很好的使用Linq的Distinct方法
- ZBar在Windows上的使用(1)-ImageMagick
- Ubuntu中修改命令终端Terminal的配色方案
- mahout调用协同过滤
- [Java]Spring入门
- javascript正则表达式和字符串RegExp and String(二)