Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is called after onConfigurationchanged() method

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.

like image 651
user2614801 Avatar asked Jul 26 '13 08:07

user2614801


People also ask

How to handle changes in screen orientation?

If you want to manually handle orientation changes in your app you must declare the "orientation" , "screenSize" , and "screenLayout" values in the android:configChanges attributes. You can declare multiple configuration values in the attribute by separating them with a pipe | character.

What are configuration changes in Android?

Configuration changes in Android refer to a set of system-level events that can strong affect application and UI behavior. These include such changes as: Orientation change (e.g., portrait to landscape); Screen size/depth change (e.g., HDMI hot-plug, orientation on newer API levels);

What method is automatically invoked when the devices running an Android application is rotated?

When you rotate your device and the screen changes orientation, Android restarts the running Activity ( onDestroy() is called, followed by onCreate()). Android does this so that your application can reload resources based on the new configuration.


1 Answers

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();
}
like image 175
g00dy Avatar answered Nov 11 '22 06:11

g00dy