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);
      }


  • 相关阅读:
    sql except 用法,找两个表中非共同拥有的
    ‘堆’出你的洪荒之力
    原来你是个这样的JVM
    变形词
    54题
    最大对称子数组
    java 线程之间通信以及notify与notifyAll区别。
    大型网站架构系列:消息队列
    剑指offer第10题
    & 和 && 区别
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/6776344.html
Copyright © 2011-2022 走看看