目录
1 PageTransformer介绍
PageTransformer是ViewPager内部定义的一个接口,用于控制ViewPager中item view的滑动效果。
我们可以通过继承PageTransformer 自行定义页面的滑动效果。
/**
* A PageTransformer is invoked whenever a visible/attached page is scrolled.
* This offers an opportunity for the application to apply a custom transformation
* to the page views using animation properties.
*
* <p>As property animation is only supported as of Android 3.0 and forward,
* setting a PageTransformer on a ViewPager on earlier platform versions will
* be ignored.</p>
*/
public interface PageTransformer {
/**
* Apply a property transformation to the given page.
*
* @param page Apply the transformation to this page
* @param position Position of page relative to the current front-and-center
* position of the pager. 0 is front and center. 1 is one full
* page position to the right, and -1 is one page position to the left.
*/
void transformPage(View page, float position);
}
参数:
- page:当前view
- position:相对当前页面的位置。左1、当前,右1对应初始position值分别为-1,0,1
右滑时:
当前View ,从0---->1;
前一个View,从-1 --->0,逐渐进入视线。
左滑时:
当前View ,从0---->-1;
后一个View,从1 --->0,逐渐进入视线。
如果定义滑动效果,一般我们关注这三个界面就足够了,也就是关注position [-1,1]这个区间。
2、画廊效果
效果图:
2.1 普通画廊
2.1.1 布局
<RelativeLayout
android:id="@+id/rl_outer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false">
<android.support.v4.view.ViewP