CB74C9551D0317305541567A87A421A5.jpg
private void initViewPager() {
// RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ChimelongApp.screenWidth * 8 / 10, ChimelongApp.screenHeight * 8 / 10);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ChimelongApp.screenWidth * 8 / 10, ViewGroup.LayoutParams.WRAP_CONTENT);
mViewPager.setLayoutParams(params);
mViewPager.setAdapter(adapter);
relativeLayout = (RelativeLayout) findViewById(R.id.relativelayout);
mViewPager.setOffscreenPageLimit(2);
mViewPager.setPageMargin(30);
mViewPager.setClipChildren(false); //用来定义他的子控件是否要在他应有的边界内进行绘制
mViewPager.setPageTransformer(false, new ZoomOutPageTransformer());
mViewPager.setCurrentItem(mPosition);
relativeLayout.setClipChildren(false);
}
//设置切换动画
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
private static final float MAX_SCALE = 1.0f;
private static final float MIN_SCALE = 0.9f;//0.85f
@Override
public void transformPage(View page, float position) {
if (position <= 1) {
float scaleFactor = MIN_SCALE + (1 - Math.abs(position)) * (MAX_SCALE - MIN_SCALE);
page.setScaleX(scaleFactor);
if (position > 0) {
page.setTranslationX(-scaleFactor * 2);
} else if (position < 0) {
page.setTranslationX(scaleFactor * 2);
}
page.setScaleY(scaleFactor);
} else {
page.setScaleX(MIN_SCALE);
page.setScaleY(MIN_SCALE);
}
}
}
<RelativeLayout
android:id="@+id/relativelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/ll1"
android:layout_marginBottom="40dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:paddingTop="10dp">
<android.support.v4.view.ViewPager
android:overScrollMode="never"
android:id="@id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false">
</android.support.v4.view.ViewPager>
</RelativeLayout>