2017-02-17 114 views
-1

我使用的方法transformPageViewPager制作的动画为page平滑动画的图

问题:我需要以固定值=> 1 scale(0.8之间,我的意思是:0.81,0.82,0.83 ...... 0.89,0.90,... 0.99)取决于位置(从0.5到1)变化,以便从小到大获得平滑的动画。

 else if (position >= 0.5F && position <= 1F) {      

       ... 
       scale = ??; 

       ViewCompat.setScaleX(page, scale); 
       ViewCompat.setScaleY(page, 0.85F); 
     } 

我试过到目前为止:

scale = (float) (0.8 + ((10*position)/100)); ==> not correct 

也是我想多else if的,如:

else if (position >= 0.5F && position <= 0.625F) { 
     scale = .97 
} 

else if (position >= 0.625F && position <= 0.75F) { 
     scale = .9 
} 

else if (position >= 0.75F && position <= 0.875F) { 
     scale = .85 
} 

else if (position >= 0.875F && position <= 1.0F) { 
     scale = .80 
} 

==>结果是这样laggy。

请帮忙,谢谢

- 更新:使用@RadekJ答案我得到相反的结果:从1到0.8:

enter image description here

+0

是的这是正确的 –

+0

为什么scaleY是0.85F不变。只是为了我的知识你为什么要编写ViewCompat.setScale。你也可以写page.setScaleY? –

+0

我只需要setScaleX,视图只需要85%的屏幕在Y规模 –

回答

1

我一直在做这种方式:

float progressStart = 0.5f 
float progressEnd = 1f; 
float progressDelta = progressEnd - progressStart; 

float progress = (position - progressStart)/progressDelta; 
if(progress>1)progress=1; 
if(progress<0)progress=0; 

float endValue = 1f; 
float startValue = 0.8f; 

float delta = endValue - startValue; 
float currentScale = startValue + delta*progress; 

ViewCompat.setScaleX(page, currentScale); 
+0

我需要相反,我从1到0.8 –

+0

请检查我的问题获得结果图片 –

+0

然后添加'progress = 1-在'currentScale'计算的行之前的进度' – RadekJ