安卓ios开发尺寸对应关系

 1、  Android与ios尺寸对应关系:

        [email protected]

        drawable-mdpi=iphone@1x

        [email protected]

        drawable-xhdpi=iphone@2x

        drawable-xxhdpi=iphone@3x

        drawable-xxxhdpi=iphone@4x

2、drawable文件夹下对应的安卓屏幕分辨率:

安卓ios开发尺寸对应关系_第1张图片

3、dp与px对应关系:

安卓ios开发尺寸对应关系_第2张图片

4、mipmap文件夹(根据Android官方的描述,mipmap仅仅用于存放APP启动图标):

安卓ios开发尺寸对应关系_第3张图片

 

5、代码

public class DensityUtil {

   public static final float getHeightInPx(Context context) {
      final float height = context.getResources().getDisplayMetrics().heightPixels;
      return height;
   }

   public static final float getWidthInPx(Context context) {
      final float width = context.getResources().getDisplayMetrics().widthPixels;
      return width;
   }

   public static final int getHeightInDp(Context context) {
      final float height = context.getResources().getDisplayMetrics().heightPixels;
      int heightInDp = px2dip(context, height);
      return heightInDp;
   }

   public static final int getWidthInDp(Context context) {
      final float height = context.getResources().getDisplayMetrics().heightPixels;
      int widthInDp = px2dip(context, height);
      return widthInDp;
   }

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

   public static int sp2px(Context context, float spValue) {
      final float scale = context.getResources().getDisplayMetrics().density;
      return (int) (spValue * scale + 0.5f);
   }
   public static String toScreenInfo(Context context) {
      DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
      return "屏幕密度:"+displayMetrics.densityDpi+"-----"+"屏幕分辨率:"+displayMetrics.widthPixels+"*"+displayMetrics.heightPixels;
   }
}

 

6、适配工具

https://blog.csdn.net/fesdgasdgasdg/article/details/82054971

Retrofit2.0+RxJava2安卓网络构架搭建,支持缓存,文件上传,cookie管理等
https://github.com/addxing/NetRequestDemo.git

 

 

你可能感兴趣的:(Android)