这更像是一个数学问题,而不是编程。
好吧,我想问你知道什么是材料设计中描述的插补器:
看起来是AccelerateDecelerateInterpolator
,但减速效果衰减得很慢。
我最好的孵化是:
public class MaterialInterpolator implements Interpolator {
@Override
public float getInterpolation(float input) {
if(input<1./3f)
return new AccelerateInterpolator().getInterpolation(input);
else
return new DecelerateInterpolator().getInterpolation(input);
}
}
这会在值之间产生差距:
Time / Value
...
0.3,0.09
0.317,0.100489
0.333,0.110889 <-- gap
0.35,0.57750005
0.367,0.599311
0.383,0.61931103
0.4,0.64
...
减速AccelerateDecelerateInterpolator:
output = accelerateDecelerateInterpolator(decelerateInterpolator(input));
private float accelerateDecelerateInterpolator(float input) {
return (float)(Math.cos((input + 1) * Math.PI) / 2.0f) + 0.5f;
}
private float decelerateInterpolator(float input) {
// return 1.0f - (1.0f - input) * (1.0f - input);
return (float)(1.0f - Math.pow((1.0f - input), 2 * mFactor)); // default factor =1.f
}
给出的费率类似于:
价值/时间曲线:</ p>
不确定开头是输出错误还是实际行为应该是输出错误
来源:http://www.google.com/design/spec/patterns/imagery-treatment.html
答案 0 :(得分:4)
这些情节看起来非常像x*(a*x+b)^2
的情节。
由于第二个根的限制等于1,它就像a*x*(x-1)^2
一样。
对其进行整合,选择a
,以便x=1
的结果为1并获得3*x^4-8*x^3+6*x^2
。
代码如下:
public class MaterialInterpolator implements Interpolator {
@Override
public float getInterpolation(float x) {
return (float) (6 * Math.pow(x, 2) - 8 * Math.pow(x, 3) + 3 * Math.pow(x, 4));
}
}
答案 1 :(得分:4)
支持库现在具有用于前Lollipop设备的插值器:FastOutLinearInInterpolator, FastOutSlowInInterpolator ,LinearOutSlowInInterpolator和PathInterpolatorCompat。
文档: http://developer.android.com/reference/android/support/v4/view/animation/package-summary.html
答案 2 :(得分:1)
Android 5现在为材料设计规范中的三条基本曲线提供插补器:
* @android:interpolator/fast_out_linear_in
* @android:interpolator/fast_out_slow_in
* @android:interpolator/linear_out_slow_in
您最有可能想要fast_out_slow_in
插补器。
答案 3 :(得分:-1)
如果您想在Android 5.0上使用它们,可以找到fast_out_slow_in.xml
插补器here的来源。
<?xml version="1.0" encoding="utf-8"?>
<pathInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:controlX1="0.4"
android:controlY1="0"
android:controlX2="0.2"
android:controlY2="1"/>