把图片从网络加载之后计算原始图片的宽和高一直得到的图片宽和高为0

    xiaoxiao2021-04-19  72

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

    最新回复(0)