viewpager的动画

网址:http://android.jobbole.com/81083/


ZoomOutPageTransformer
当在相邻界面滑动时,这个page transformer使页面收缩并褪色。当页面越靠近中心,它将渐渐还原到正常大小并且图像渐入。

Depth Page Transformer
这个page transformer使用默认动画的屏幕左滑动画。但是为右滑使用一种“潜藏”效果的动画。潜藏动画将page淡出,并且线性缩小它。


mPager.setPageTransformer(true, new ZoomOutPageTransformer());

ZoomOutPageTransformer .java 类

package com . zhy . view ;
 
import android . annotation . SuppressLint ;
import android . support . v4 . view . ViewPager ;
import android . util . Log ;
import android . view . View ;
 
public class ZoomOutPageTransformer implements ViewPager . PageTransformer
{
private static final float MIN_SCALE = 0.85f ;//该值是滑动时候显示的大小(滑动中)
private static final float MIN_ALPHA = 0.5f ;
 
@SuppressLint ( "NewApi" )
public void transformPage ( View view , float position )
{
int pageWidth = view . getWidth ( ) ;
int pageHeight = view . getHeight ( ) ;
 
Log . e ( "TAG" , view + " , " + position + "" ) ;
 
if ( position < - 1 )
{ // [-Infinity,-1)
// This page is way off-screen to the left.
view . setAlpha ( 0 ) ;
 
} else if ( position <= 1 ) //a页滑动至b页 ; a页从 0.0 -1 ;b页从1 ~ 0.0
{ // [-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 ) ;
} else
{
view . setTranslationX ( - horzMargin + vertMargin / 2 ) ;
}
 
// 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 ) ) ;
 
} else
{ // (1,+Infinity]
// This page is way off-screen to the right.
view . setAlpha ( 0 ) ;
}
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值