我尝试了很多次,但都无法解决。我想通过不断变化的垂直偏差来为视图设置动画。那我该如何打败呢?
ValueAnimator animator = ValueAnimator.ofInt(100, percent);
animator.setDuration(2000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
ViewGroup.LayoutParams params = mViewTop.getLayoutParams();
float v = ((Float.parseFloat(animation.getAnimatedValue().toString())) / 100f) -0.1f;
if (v<0){
v=0;
}
params.verticalBias = v;
mViewTop.setLayoutParams(params);
}
});
animator.start();
答案 0 :(得分:3)
您需要像下面一样进行更改 你做错了演员表需要改变
ValueAnimator animator = ValueAnimator.ofInt(100, percent);
animator.setDuration(2000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) mViewTop.getLayoutParams();
float v = ((Float.parseFloat(animation.getAnimatedValue().toString())) / 100f) -0.1f;
if (v<0){
v=0;
}
params.verticalBias = v;
mViewTop.setLayoutParams(params);
}
});
animator.start();