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.
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.
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);
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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With