Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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]}

like image 674
Shlomi Schwartz Avatar asked Jan 05 '12 10:01

Shlomi Schwartz


People also ask

What is the use of setContentView () method?

SetContentView(View, ViewGroup+LayoutParams)Set the activity content from a layout resource.

Why do we need to call setContentView () in onCreate () of activity class?

As onCreate() of an Activity is called only once, this is the point where most initialization should go: calling setContentView(int) to inflate the activity's UI, using findViewById to programmatically interact with widgets in the UI, calling managedQuery(android.

What is Setcontent view in Android?

setContentView(View) is a method exclusively available for Activity. Internally it calls the setContentView(View) of Window. This method sets the activity content to an explicit view. SetContentView() method is 3 types. setContentView(int resourceId)

What method of the Activity class is used to set the view layout for an activity?

setContentView(int layoutid) - method of activity class. It shows layout on screen.


1 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);        
     }      
});  
like image 136
Lumis Avatar answered Nov 16 '22 01:11

Lumis