这是我拥有的代码。它对于水平转换动画效果很好。我想垂直变换ViewPager过渡动画。
public class AccordionPageTransformer implements ViewPager.PageTransformer {
@Override
public void transformPage(View page, float position) {
// Counteract the default slide transition
page.setTranslationX(-position * page.getWidth());
page.setPivotX(position < 0 ? 0 : page.getWidth());
page.setScaleX(1 - Math.abs(position));
}}
答案 0 :(得分:0)
尝试使用ViewPager,
if (position < -1) {
page.setAlpha(0);
} else if (position <= 1) {
page.setAlpha(1);
// Counteract the default slide transition
page.setTranslationX(page.getWidth() * -position);
//Set Y position to swipe in from top
float yPosition = position * page.getHeight();
page.setTranslationY(yPosition);
} else {
page.setAlpha(0);
}
或者您也可以使用ViewPager2它提供单行代码以使垂直滚动成为可能,
myViewPager2.setOrientation(ViewPager2.ORIENTATION_VERTICAL);