1 package com.example.nanchen.mydateviewdemo.view; android.content.Context; 4 import android.content.res.Resources; * 辅助类 8 * nanchen 10 * @date 16-8-10 上午11:39 ViewUtil { * 获取屏幕的宽度 context getScreenWidth(Context context) { 19 Resources res = context.getResources(); 20 return res.getDisplayMetrics().widthPixels; 21 } * 获取屏幕高度 context getScreenHeight(Context context) { 29 Resources res = context.getResources(); 30 return res.getDisplayMetrics().heightPixels; 31 } * 描述:根据分辨率获得字体大小. 35 * screenWidth the screen width screenHeight the screen height textSize the text size the int resizeTextSize(int screenWidth,int screenHeight,int textSize){ 42 float ratio = 1; 43 try { 44 float ratioWidth = (float)screenWidth / 480; 45 float ratioHeight = (float)screenHeight / 800; 46 ratio = Math.min(ratioWidth, ratioHeight); 47 } catch (Exception e) { 48 } 49 return Math.round(textSize * ratio); 50 } * 54 * 描述:dip转换为px context dipValue dip2px(Context context, float dipValue) { scale = context.getResources().getDisplayMetrics().density; 62 return Math.round(dipValue * scale); 63 } * 67 * 描述:px转换为dip context pxValue px2dip(Context context, float pxValue) { scale = context.getResources().getDisplayMetrics().density; 75 return Math.round(pxValue / scale); 76 } * 80 * 描述:px转换为sp context pxValue px2sp(Context context, float pxValue) { scale = context.getResources().getDisplayMetrics().scaledDensity; 88 return Math.round(pxValue / scale); 89 } * 93 * 描述:sp转换为px context spValue sp2px(Context context, float spValue) { scale = context.getResources().getDisplayMetrics().scaledDensity; 101 return Math.round(spValue * scale); 102 } 103 }
10)
WeekGridAdapter