What is called after onConfigurationchanged() method
Asked Answered
C

1

7

After screen rotating, the height of one of view object is changed, I want to know the height value in pixel.

The onConfigurationChanged method is likely called before view finishing rotation. So if I measure the view size in this method , the size is still the value of rotation before.

The problem is how can I get the view size value after rotation finish Without reconstructing Activity.

Carlita answered 26/7, 2013 at 8:4 Comment(2)
You can always check this in the OnResume() method, since it's called after the rotation.Objectify
thank for your answer.It seems does not run OnResume()method since I use android:configChanges="orientation|screenSize" in AndroidManifest.xml file. I set the breakpoint in OnResume ,but didnot stop when ratation.Carlita
O
4

One possible solution:

private int viewHeight = 0;
View view = findViewByID(R.id.idOfTheView);
view.getViewTreeObserver().addOnGlobalLayoutListener( 
    new OnGlobalLayoutListener(){
        @Override
        public void onGlobalLayout() {
            viewHeight = view.getHeight();
        }

OR

@Override
public void onResume(){
  int viewHeight = 0;
  View view = findViewByID(R.id.idOfTheView);
  viewHeight  = view.getHeight();
}
Objectify answered 26/7, 2013 at 8:48 Comment(4)
thank you for your answer, I think the onResume() won't run since I set android:configChanges="orientation|screenSize" in AndroidManifest.xml file. I will study the way of OnGlobalLayoutListener.Carlita
OnResume() is always called when these's an orientation change, because the whole Activity gets re-created.Objectify
I just read the programming guide article about rotation again. It said that above the API level 12 , configuration change does not restart your activity, the reference’s address is developer.android.com/guide/topics/resources/… in this article there is a paragraph like this Now, when one of these configurations change, MyActivity does not restart. Instead, the MyActivity receives a call to onConfigurationChanged(). ......Carlita
thanks ,the problem is solved by adding GlobalLayoutListener.Carlita

© 2022 - 2024 — McMap. All rights reserved.