Question

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.

Était-ce utile?

La solution

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();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top