android - Setting View visibility to Invisible and getting the dimensions -


I have an image that has visibility set gone I'm trying to set a bitmap resource on it and reveal it.

I know that the Dimensions of ImageView (which I need to greet my bitmap properly) is zero when this visibility is still Gone , so I Bitmapsync Task Run before setting this line to code.

  Image View Post Image View = (see image) getActivity (). FindViewById (R.id.post_image); // Set it as visible to take the position needed for bitmap computing. PostImageView.setVisibility (see. INVISIBLE);  

The dimensions still come back to zero and further tests, the image view takes some time before its visibility is again set on Invisible until the dimension is available. Waiting till then is a time loop inside the violent task, but I want to know that there is a better way of doing this?

My current code for AsyncTask:

@ Override protected bitmap doInBackground (zero ... voids) {Log.i (TAG, "BitMapWorkWorker Startup."); While (mImageView.getWidth () == 0) {// Wait for ImageView to prepare Log.i (TAG, "asd"); } Int reqWidth = mImageView.getWidth () == 1920: mImageView.getWidth (); Int reqHeight = mImageView.getHeight () == 0? 1080: mImageView.getHeight (); Logs. I (tag, "dimension (required):" + rectitude + "x" + reckhhite); // decode and scale image bitmapfactor. Option option = new bitmapfactor Option (); Options.inJustDecodeBounds = True; Bitmapfichtor Decodfile (amcrint-photo-path, option); Log.i (tag, "dimension (source):" + options.outWidth + "X" + options.outHeight); Options.inSampleSize = Count InSampleSize (option, reqWidth, reqHyight); Options.inJustDecodeBounds = Wrong; Bitmap imagebitmap = bitmapfirenet Decodefile (mcurrentphotopath, option); Logs. I (tag, "dimension (bitmap):" + image bitmap .getWidth () + "X" + imageBitmap.getHeight ()); Return image; }

Try adding the layout listener, wait for the layout to be measured:

Last Image View Post Image View = (ImageView) getActivity (). FindViewById (R.id.post_image); PostImageView.addOnLayoutChangeListener (see the new OnLayoutChangeListener) {@ Override Public Wide On Layout Change (see View, Int i, Int i2, Int i3, Int i4, Int i5, Int 6, Int i7, Int Eye 8) {postImageView .removeOnLayoutChangeListener (this); Logs. A (Tag, "W:" + Post Imageview .getWidth () + "H:" + Post Image ViewGateHight ());}}); PostImageView.setVisibility (View.INVISIBLE);

Comments