目前我正在使用ViewPager
来制作旋转木马效果菜单
但是我面临一些初始化问题
这就是我希望我的旋转木马在应用程序启动后看起来像的方式,看看第二个瓷砖是视频磁贴,它比第一个瓷砖更小,也就是音乐磁贴
然而,我得到的是像应用程序启动后的 (如果我没有移动它或拖动它)
为了使旋转木马看起来像第一张图像,我需要先手动移动或拖动它,然后一切看起来应该是什么
以下是我设置视图页面的代码段
pageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments);
pager = (ViewPager) findViewById(R.id.viewpager);
pager.setPageMargin(-700);//so that it look like carousel
pager.setOffscreenPageLimit(Menu.size());
pager.setAdapter(pageAdapter);
pager.setOnPageChangeListener(pageAdapter);
pager.setPageTransformer(true, new ZoomOutPageTransformer());
以下是我的代码段,其中包含了页面之间动画的zoomoutpagetransformer
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.85f;
private static final float MIN_ALPHA = 0.5f;
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);
} else if (position <= 1) { // [-1,1]
// Modify the default slide transition to shrink the page as well
float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
float vertMargin = pageHeight * (1 - scaleFactor) / 2;
float horzMargin = pageWidth * (1 - scaleFactor) / 2;
if (position < 0) {
view.setTranslationX(horzMargin - vertMargin / 2);// positive
} else {
view.setTranslationX(-horzMargin + vertMargin / 2);// negative
}
// Scale the page down (between MIN_SCALE and 1)
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);
// Fade the page relative to its size.
view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA));
textview.setText(String.valueOf(scaleFactor) + "\n" + String.valueOf(vertMargin) + "\n"
+ String.valueOf(horzMargin));
} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}
}
任何人都知道如何在应用程序启动后让它看起来应该是什么,而不是先移动或拖动它?