31. transformPageで
視差を生み出す
• スライドの都合上先に説明
• position < -1, position > 1 は画面に表示されていないView
• -1 <= position < =0 は画面左側に表示されているView
• 0 < position < =1 は画面右側に表示されているView
• FragmentでViewHolderを生成し、Tagとして設定
• setTranslationXでスワイプの動きとずらす
• transitionは自作ViewHolderのメソッド
32. @Override
public void transformPage(View page, float position) {
if (position <= -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
} else if (position <= 1) {
((ViewHolder)page.getTag()).transition(page, position);
} else { // (1,+Infinity]
// This page is way off-screen to the right.
}
}
@Override
public void transition(View page, float position) {
if (-1 < position && position < 0) {
// left
leftIcon.setTranslationX(position * page.getWidth() * 2);
rightIcon.setTranslationX(-position * page.getWidth() / 4);
} else if (0 <= position && position <= 1) {
// right
leftIcon.setTranslationX(position * page.getWidth() * 2);
rightIcon.setTranslationX(position * page.getWidth());
}
centerIcon.setTranslationX(-position * page.getWidth());
}