我是靠谱客的博主 乐观鞋子,这篇文章主要介绍android中代码设置控件的一些属性,现在分享给大家,希望可以做个参考。

  1. public class DensityUtil {  
  2.   
  3.     /** 
  4.      * 根据手机的分辨率从 dp 的单位 转成为 px(像素) 
  5.      */  
  6.     public static int dip2px(Context context, float dpValue) {  
  7.         final float scale = context.getResources().getDisplayMetrics().density;  
  8.         return (int) (dpValue * scale + 0.5f);  
  9.     }  
  10.   
  11.     /** 
  12.      * 根据手机的分辨率从 px(像素) 的单位 转成为 dp 
  13.      */  
  14.     public static int px2dip(Context context, float pxValue) {  
  15.         final float scale = context.getResources().getDisplayMetrics().density;  
  16.         return (int) (pxValue / scale + 0.5f);  
  17.     }  
  18. }

最后

以上就是乐观鞋子最近收集整理的关于android中代码设置控件的一些属性的全部内容,更多相关android中代码设置控件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(108)

评论列表共有 0 条评论

立即
投稿
返回
顶部