获取图片资源过时方法替换:getResources().getDrawable(R.drawable.img);替换

获取图片资源过时方法替换

① Drawable drawable = ContextCompat.getDrawable(context,R.drawable.img); //recommend

Drawable getDrawable(int id, Resources.Theme theme);// above API19  , 第二个参数@theme可以为空值.或Context.getDrawable(int)



获取屏幕宽高过时方法替换:

 
  

WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);

int width = wm.getDefaultDisplay().getWidth();//过时

int height = wm.getDefaultDisplay().getHeight();//过时

替换方法

WindowManager manager = this.getWindowManager();

DisplayMetrics outMetrics = new DisplayMetrics();

manager.getDefaultDisplay().getMetrics(outMetrics);

int width2 = outMetrics.widthPixels;

int height2 = outMetrics.heightPixels;

或者:

Resources resources = this.getResources();

DisplayMetrics dm = resources.getDisplayMetrics();

float density1 = dm.density;

int width3 = dm.widthPixels;

int height3 = dm.heightPixels;




你可能感兴趣的:(android,笔记)