有没有办法在一个动画中向下和向上旋转像亨德尔这样的图像 像这样animation is here what i want like 3d view..
答案 0 :(得分:3)
答案很简单,您必须设置视图的轴心,以便在旋转时可以按轴旋转视图。 (在您的情况下,此代码将保持视图底部相同并为视图顶部设置动画,就像您在视频中显示的那样)
根据图像,如果杠杆底部框是图像高度的25%,则必须计算图像的轴旋转25%。
View v = findViewById(R.id.animate_view);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
int percentageHeightOfBox = 25;
int height = v.getMeasuredHeight();
v.setPivotX(v.getMeasuredWidth() / 2);
v.setPivotY(height - ((height * percentageHeightOfBox) / 100));
ValueAnimator animator = ValueAnimator.ofFloat(0.0f, 90f);
animator.setDuration(1000);
animator.setRepeatCount(ObjectAnimator.INFINITE);
animator.setRepeatMode(ObjectAnimator.REVERSE);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float rotate = Float.parseFloat(animation.getAnimatedValue().toString());
v.setRotationX(rotate);
}
});
animator.start();
}
});
答案 1 :(得分:2)
试试这个。
ObjectAnimator animation = ObjectAnimator.ofFloat(yourImageView, "rotationX", 0.0f, 90f);
animation.setDuration(1000);
animation.setRepeatCount(ObjectAnimator.INFINITE);
animation.setRepeatMode(ObjectAnimator.REVERSE);
animation.setInterpolator(new AccelerateDecelerateInterpolator());
animation.start();