Android-Universal-Image-Loader ImagePager - 如何在设备旋转时避免活动回到第一页

时间:2013-02-18 01:37:09

标签: universal-image-loader

当我旋转设备时,ImagePagerActivity显示第1页(在滚动视图中)。怎么解决?感谢。

1 个答案:

答案 0 :(得分:1)

public class ImagePagerActivity extends BaseActivity {

    private static final String STATE_POSITION = "STATE_POSITION";

    ViewPager pager;

    public void onCreate(Bundle savedInstanceState) {
        // ...

        if (savedInstanceState != null) {
            pagerPosition = savedInstanceState.getInt(STATE_POSITION);
        }

        // ...

        pager.setCurrentItem(pagerPosition);
    }

    public void onSaveInstanceState(Bundle outState) {
        outState.putInt(STATE_POSITION, pager.getCurrentItem());
    }

    ...
}