开发者

getBounds returning height & width 0

开发者 https://www.devze.com 2023-03-22 05:05 出处:网络
photo = (ImageView) findViewById(R.id.image1); photo.setImageBitmap(pic); Drawable drawable = photo.getDrawable();
    photo = (ImageView) findViewById(R.id.image1);
    photo.setImageBitmap(pic);      
    Drawable drawable = photo.getDrawable();
    imageBounds = dra开发者_运维知识库wable.getBounds();
    int scaledHeight = imageBounds.height();
    int scaledWidth = imageBounds.width();

Here scaledHeight & scaledWidth are zero. But i am getting the size of image correctly.

    int intrinsicHeight = drawable.getIntrinsicHeight();
    int intrinsicWidth = drawable.getIntrinsicWidth();

What is the problem imageBounds.height();


I think you use "photo" in the onCreate method. There, the ImageView dimensions are not still defined and I suggest you to put your code in the onWindowFocusChanged method, when "hasFocus" is true.

0

精彩评论

暂无评论...
验证码 换一张
取 消