Resources res = mContext.getResources(); BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, R.drawable.home_common_icon_default, opts); opts.inSampleSize = 1; opts.inJustDecodeBounds = false; int w = opts.outWidth; int h = opts.outHeight; LogUtil.e("+++++++++++++++++++++++++++++++++++++++++++++++++:"); LogUtil.e("w:" + w); LogUtil.e("h:" + h); int width = DensityUtil.dip2px(mContext, w / 2); int height = DensityUtil.dip2px(mContext, h / 2); LogUtil.e("" + width); LogUtil.e("height:" + height); LogUtil.e("getDensity:" + DensityUtil.getDensity(mContext)); LogUtil.e("+++++++++++++++++++++++++++++++++++++++++++++++++:");
因为默认获取的不是真实宽高,是缩放比例的宽高