android中dp和px的转换
来源:互联网 发布:库存软件 手机免费版 编辑:程序博客网 时间:2024/04/29 01:49
Android中由于需要适配不同分辨率的屏幕,所以我们需要对dp和px进行转换。在转换之前,首先我们需要计算屏幕的像素密度,再按像素密度,成比例转换。
public class DipUtil {public static int dip2px(Context context, float dipValue) {final float scale = context.getResources().getDisplayMetrics().density;return (int) (dipValue * scale + 0.5f);}public static int px2dip(Context context, float pxValue) {final float scale = context.getResources().getDisplayMetrics().density;return (int) (pxValue / scale + 0.5f);}public static int getWindowWidth(Context context) {WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE);int width = wm.getDefaultDisplay().getWidth();return width ;}public static int getWindowHeight(Context context) {WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);int height = wm.getDefaultDisplay().getHeight();return height ;}}
0 0
- android中dp和px的转换
- Android 中 px和dp 的转换
- Android中dp和px转换类
- Android中dp和px之间进行转换的代码
- Android中dp、sp、px的转换和区别
- Android中px和dp的互相转换
- Android中dp、sp、px的转换和区别。
- Android中px和dp的互相转换
- android中px和dp的相互转换
- Android中dp、sp、px的转换和区别。
- android中dp和px之间转换的工具类
- Android中dp和px之间的转换
- Android中dp和px之间进行转换的代码
- (转)Android中dp、sp、px的转换和区别
- Android开发中dp,sp和px之间的转换
- Android中dp 与 px 的转换
- android中dp与px的转换
- android DP和PX之间的转换
- 2014年公认最好的一篇文章,你看了没有?
- 项目中引用别的资源项目
- 动态改变tableview的cell的高度
- Qt富文本处理
- facebook开源项目
- android中dp和px的转换
- DM8168,AM3894,DM8148,AM3874获取sink设备EDID方法
- 代码实现EditText的限制性输入字符内容和多少
- JAVA对比C语言,从入门到精通学习JAVA
- ios开发系列之懒加载
- Java中只有按值传递,没有按引用传递!
- Bicoloring
- hql:一对多和多对多的结合
- Malicious Stored XSS Vulnerability in PayPal, Find Bitdefender Researchers