Android 常用工具类之 DimenUtil
public class DimenUtil {
/** sp转换成px */
public static int sp2px(float spValue) {
float fontScale = MyApplication.getContext().getResources().getDisplayMetrics().scaledDensity;
return (int) (spValue * fontScale + 0.5f);
}
/** px转换成sp */
public static int px2sp(float pxValue) {
float fontScale = MyApplication.getContext().getResources().getDisplayMetrics().density;
return (int) (pxValue / fontScale + 0.5f);
}
/** dip转换成px */
public static int dip2px(float dipValue) {
float scale = MyApplication.getContext().getResources().getDisplayMetrics().scaledDensity;
return (int) (dipValue * scale + 0.5f);
}
/** px转换成dip */
public static int px2dip(float pxValue) {
float scale = MyApplication.getContext().getResources().getDisplayMetrics().scaledDensity;
return (int) (pxValue / scale + 0.5f);
}
}
Android 常用工具类之 DimenUtil的更多相关文章
- 53. Android常用工具类
主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java.目前包括HttpUtils.DownloadManagerPro.ShellUtils.PackageUtils.Prefer ...
- Android 常用工具类之SPUtil,可以修改默认sp文件的路径
参考: 1. 利用Java反射机制改变SharedPreferences存储路径 Singleton1900 2. Android快速开发系列 10个常用工具类 Hongyang import ...
- 【转】Android常用工具类
主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java. 目前包括HttpUtils.DownloadManagerPro.ShellUtils.PackageUtils.Prefe ...
- android常用工具类
import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkIn ...
- Android 常用工具类之 ScreenUtil
需求: 截屏 参考 : Android开发:截屏 screenshot 功能小结 package bvb.de.openadbwireless.utils; import android.app ...
- Android 常用工具类之LogUtil,可以定位到代码行,双击跳转
package cn.utils; import android.util.Log; public class LogUtils { public static boolean isDebug = t ...
- Android常用工具类封装---SharedPreferencesUtil
SharedPreferences常用于保存一些简单的数据,如记录用户操作的配置等,使用简单. public class SharedPreferencesUtil { // ...
- Android 常用工具类之DeviceInfoUtil
public class DeviceInfoUtil { private static WifiManager wifiManager = null; // wifi是否已连接 public sta ...
- Android 常用工具类之RuntimeUtil
public class RuntimeUtil { /** 通过查询su文件的方式判断手机是否root */ public static boolean hasRootedSilent() { re ...
随机推荐
- java枚举使用详解(转)
在实际编程中,往往存在着这样的"数据集",它们的数值在程序中是稳定的,而且"数据集"中的元素是有限的. 例如星期一到星期日七个数据元素组成了一周的"数 ...
- Eclipse中文注释乱码解决
将别人的项目或JAVA文件导入到自己的Eclipse中时,常常会出现JAVA文件的中文注释变成乱码的情况,主要原因就是别人的IDE编码格式和自己的Eclipse编码格式不同. 总结网上的建议和自己的体 ...
- FreeMarker惯用内置函数
1.sequence?first 返回sequence的第一个值. 2.sequence?last 返回sequence的最后一个值. 3.sequence?reverse 将sequence的现有顺 ...
- Python模块(scapy)
scapy scapy相当于linux的tcpdump的功能
- 复制中的NOT FOR REPLICATION
错误#1 10:51 2012-9-4sp_MSget_repl_commands 重复键插入解答#1 修改distribution库下sp_MSget_repl_commands 存储过程decla ...
- 【未完待补充】linux 设置So动态库链接路径
缘起 安装python的包Rtree(Rtree-0.8.2),但需要先安装C语言依赖包spatialindex-src(spatialindex-src-1.8.5).在安装完spatialinde ...
- cocos2dx 3.x以上(Sprite精灵类的相关属性与创建)
// // MainScene.cpp // helloworld // // Created by apple on 16/9/19. // // #include "MainSce ...
- 查看oracle 数据库的DBID
(1)使用rman查看$ rman target /Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jun 12 03:20:19 2 ...
- Oracle 11g RAC INS-06006 Passwordless SSH connectivity not set up between the following node(s)
安装11g RAC的grid时,在Test互信的时候报错INS-06006 Passwordless SSH connectivity not set up between the following ...
- iOS6:在你的App内使用Passbook
前言 这是一篇翻译,感谢Jonathan Tang. 原文地址:iOS 6 Tutorial: Integrating Passbook into Your Applications 另外,看到另一篇 ...