【问题标题】:Smooth animation for a view视图的平滑动画
【发布时间】:2017-02-17 19:46:55
【问题描述】:

我正在使用transformPage 方法在ViewPager 中为page 制作动画:

问题:我需要修复scale 的值(介于 0.8 => 1 之间,我的意思是: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
}

==> 结果太慢了。

请帮忙,谢谢

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

【问题讨论】:

  • 是的,这是正确的
  • 为什么 scaleY 是 0.85F 常数。就我所知,您为什么要编写 ViewCompat.setScale。也可以写page.setScaleY?
  • 我只需要setScaleX,视图在Y轴上只占屏幕的85%

标签: java android animation android-viewpager


【解决方案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);

【讨论】:

  • 我需要反过来,我从 1 变为 0.8
  • 请检查我的问题以获取结果图片
  • 然后在计算currentScale的行前添加progress = 1-progress
  • 欢迎您!您可以简单地将endValuestartValue 切换以使其更具可读性;)
  • 嗨,如果你能解决这个问题,请帮助我:stackoverflow.com/questions/44245228/…谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多