android不同機型上介面適配問題

來源:互聯網
上載者:User

標籤: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);  }


android不同機型上介面適配問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.