Bitmap image = ((BitmapDrawable)
details_picture.getDrawable()).getBitmap();
//把imageview转换成bitmap
imagewidth = image.getWidth();
imageHeight = image.getHeight();
在onCreate方法中,控件其实还没有画好,也就是说当onCreate方法执行完了之后,才开始绘制控件,所以在onCreate方法中获取width和height返回的值是0。但是我又想onResume方法是不是可以呢?后来发现还是不行!我自定义了ImageView,然后打印量log日志,发现果然是这样,onCreate和onResume方法执行完了之后,才开始执行控件的测量(onMeasure)和绘制(onDraw)方法。
所以测算图片宽和高的时候要在上面的方法之后测试
转载请注明原文地址: https://ju.6miu.com/read-675678.html