ViewPager卡片效果(一)——画廊效果

 

目录

1 PageTransformer介绍

2、画廊效果

2.1 普通画廊

2.1.1 布局

2.1.2 定义自己的PageTransformer

2.1.3 使用

2.2 3D画廊

Preference


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
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值