zoukankan      html  css  js  c++  java
  • Density

    package com.k1.frame.utils;
    
    import android.content.Context;
    import android.util.DisplayMetrics;
    
    public class Density {
    
        public static final float DEFAULT_SCALE = 2;
    
        private static float scale = 1.0f;
        private static float fontScale = 1.0f;
        private static int statusBarHeight = 40;
        private static int screenWidth = 720;
        private static int screenHeight = 1280;
    
        public static void init (Context context) {
            DisplayMetrics dm = context.getResources().getDisplayMetrics();
            scale = dm.density;
            fontScale = dm.scaledDensity;
            screenWidth = dm.widthPixels;
            screenHeight = dm.heightPixels;
            statusBarHeight = getStatusBarHeight(context);
        }
    
        private static int getStatusBarHeight(Context context) {
            int result = 0;
            int resourceId = context.getResources().getIdentifier(
                    "status_bar_height", "dimen", "android");
            if (resourceId > 0) {
                result = context.getResources().getDimensionPixelSize(resourceId);
            }
            return result;
        }
        
        public static int statusBarHeight() {
            return statusBarHeight;
        }
    
        public static int screenWidth() {
            return screenWidth;
        }
        
        public static int screenHeight() {
            return screenHeight;
        }
    
        public static int dip2px(float dpValue) {
            return (int) (dpValue * scale + 0.5f);
        }
    
        public static int px2dip(float pxValue) {
            return (int) (pxValue / scale + 0.5f);
        }
    
        public static int px2sp(float pxValue) {
            return (int) (pxValue / fontScale + 0.5f);
        }
    
        public static int sp2px(float spValue) {
            return (int) (spValue * fontScale + 0.5f);
        }
    }
  • 相关阅读:
    poj2502(最短路)
    poj1511(最小环和)
    uva11090(spfa判负环)
    hdu4370(spfa最短路最小环)
    uva10561(SG)
    uvalive5059(SG)
    uvaliva3905(扫描线)
    scu4445(模拟)
    uvalive3902(树上的最优化 贪心)
    scu4444(完全图最短路)
  • 原文地址:https://www.cnblogs.com/g-sheng/p/5406520.html
Copyright © 2011-2022 走看看