Question

I'm using SwipeView (http://jasonfry.co.uk/blog/android-swipeview/) inside my activity's layout to display several pages. Moreover, I want to handle the orientation changes manually so I added

android:configChanges="orientation|keyboardHidden|screenSize"

into the application's manifest, so that onDestroy/onCreate are not called. Unfortunately, by doing this, the elements inside the swipeview are not resized accordingly. I already tried the following methods:

  • invalidate
  • requestLayout
  • forceLayout

None of them did the trick! Any help would be appreciated. Thanks

Was it helpful?

Solution

In case anyone struggles with this, I finally found a solution. The trick was to request layout not on the swipeview itself but rather on getChildContainer().

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    SwipeView swipeView = (SwipeView)findViewById(R.id.swipeView);
    int pageWidth = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
    swipeView.setPageWidth(pageWidth);
    for ( int i = 0; i < swipeView.getChildContainer().getChildCount(); i++ )
        swipeView.getChildContainer().getChildAt(i).getLayoutParams().width = pageWidth;
    swipeView.getChildContainer().requestLayout();
    swipeView.scrollToPage(swipeView.getCurrentPage());     
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top