效果實現(xiàn)
圖中所示,當(dāng)page1向左滑動的時候page1 y軸瞬時針進(jìn)行旋轉(zhuǎn) x軸進(jìn)行旋轉(zhuǎn),page2 則相反,(x y軸角度旋轉(zhuǎn)差 可以實現(xiàn)z軸旋轉(zhuǎn)的效果).
code
viewPager.setPageTransformer(true, new ViewPager.PageTransformer() {
@Override public void transformPage(View view, float position) {
float mRot = (15.0f * position);
if (position < -1) {
ViewCompat.setRotationX(view, 0);
ViewCompat.setRotationY(view, 0);
ViewCompat.setRotation(view, 0);
} else if (position >= 1) {
ViewCompat.setRotationX(view, 0);
ViewCompat.setRotationY(view, 0);
ViewCompat.setRotation(view, 0);
} else if (position > 0) {//->[0,1] 向左滑動時候page2 postion的偏移值 從0到1變化過程
ViewCompat.setPivotX(view, view.getMeasuredWidth() / 3);
ViewCompat.setPivotY(view, view.getMeasuredHeight());
ViewCompat.setRotationY(view, -mRot / 2);
ViewCompat.setRotationX(view, mRot / 3);
} else if (position < 0) {//[<- [0,-1]]向左滑動時候page1 postion的偏移值 從0到0-1變化過程
ViewCompat.setPivotX(view, view.getMeasuredWidth() / 3);
ViewCompat.setPivotY(view, view.getMeasuredHeight());
ViewCompat.setRotationY(view, -mRot / 2);
ViewCompat.setRotationX(view, -mRot / 3);
}
}
});