Home » Android » image – Android – Is there any event triggered when activity.setContentView has finished rendering?

image – Android – Is there any event triggered when activity.setContentView has finished rendering?

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’m trying to get values from myImageView.getImageMatrix() method once my activity is ready.
I tried using the onCreate() , onStart() , onResume() methods but the matrix I get is the default.

If I call myImageView.getImageMatrix() triggered by an OnClickListener, after my activity is visible, I get the right values.


Just to be more clear:

  • calling getImageMatrix onStart = Matrix{[1.0, 0.0, 0.0][0.0, 1.0,
    0.0][0.0, 0.0, 1.0]}

  • calling getImageMatrix onClick = Matrix{[0.77488154, 0.0,
    7.6717987][0.0, 0.77488154, 0.0][0.0, 0.0,
    1.0]}

How to&Answers:

You can also try this method:

ImageView myImageView = (ImageView) findViewById(R.id.myImageView);
ViewTreeObserver vto = myImageView.getViewTreeObserver();      
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {          
     @Override          
     public void onGlobalLayout() {              
        // do something now when the object is loaded 
        // e.g. find the real size of it etc          
        myImageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);        
     }      
});  

Answer:

I am not 100% but I needed to know something similar for my development and I found out that onWindowFocusChanged() is called when the view is loaded. I am not sure if that fills your needs or not.

Answer:

Maybe you can use an onLayoutChangeListener but I am not sure.

Answer:

Perhaps you could use an AsyncTask (http://developer.android.com/reference/android/os/AsyncTask.html) that monitors whether the ImageView has loaded (maybe does not equal null).

You could display a progess dialog in onProgressUpdate and then continue your code from onPostExecute.