zoukankan      html  css  js  c++  java
  • android不同机型上界面适配问题

    android中长度有:dp(或者dip device independent pixels)一种基于屏幕密度的抽象单位。在每英寸160点的显示器上。1dp=1px。

    不同设备有不同的显示效果。这个和设备硬件有关。布局时尽量使用单位dp;sp(Scaled Pixels)主要用于字体显示,与刻度无关的一种像素,与dp类似。可是能够依据用户的字体大小首选项进行缩放。px:表示屏幕实际的象素。TextView 的方法setTextSize使用sp作为字号单位。Point的方法setTextSize使用px为单位。以下是转换放方法:

      public static int px2sp(Context context, float pxValue) {
        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
        return (int) (pxValue / fontScale + 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 dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
      }


  • 相关阅读:
    Spring:@ConfigurationProperties配置绑定
    Linux:性能诊断
    【第二章】:深浅拷贝剖析
    【第二章】:模块和运算符
    python 扩展注册功能装饰器举例
    python 函数 之 用户注册register()
    python 之 函数 基础
    python 函数
    python 文件操作
    python 的 数据类型
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/6776344.html
Copyright © 2011-2022 走看看