android - How to get the height and width of ImageView? -
i trying height & width of imageview bot it's returning 0
public class fullscreenimage extends fragmentactivity { imageview full_view; int width; int height; @override protected void oncreate(bundle arg0) { super.oncreate(arg0); setcontentview(r.layout.full_screen); full_view = (imageview)findviewbyid(r.id.full_view); bundle bundle=getintent().getextras(); byte[] image= bundle.getbytearray("image"); width = full_view.getwidth(); height = full_view.getheight(); bitmap theimage = bitmapfactory.decodebytearray(image, 0, image.length); bitmap resized = bitmap.createscaledbitmap(theimage,width , height, true); full_view.setimagebitmap(resized); } }
please me, how can it?
a common mistake made new android developers use width , height of view inside constructor. when view’s constructor called, android doesn't know yet how big view be, sizes set zero. real sizes calculated during layout stage, occurs after construction before drawn. can use onsizechanged()
method notified of values when known, or can use getwidth()
, getheight()
methods later, such in ondraw()
method.
Comments
Post a Comment