复制Page 0和Page 1中的背景图片,尝试在onPageScrolled回调中改变图片偏移量即可达到目的~
FragmentPic 是一个简单的片段,只有一个 imageview 孩子作为 iv
/*this method change position of image to move it against its parent and make it looks static to the screen */
public void changeImageOffset(int offset) {
RelativeLayout.LayoutParams lp = (LayoutParams) iv
.getLayoutParams();
lp.leftMargin = offset;
lp.rightMargin = -offset;
iv.setLayoutParams(lp);
}
在 viewPager 活动中
mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrolled(int position, float arg1, int arg2) {
((FragmentPic) mAdapter.getItem(position))
.changeImageOffset(arg2);
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
上面的代码可以使page1静态,page2从右到左覆盖它。