实现一个仪表:
指针可以旋转,UI提供指针。
@BindView(R.id.iv_pointer)
ImageView ivPointer;
...
private void setPointer(float temp){
float proportion = 0.925f;//温度与刻度的比例
float angle = proportion*temp;
if (Math.abs(angle - lastTemp) < 0.5){
return;
}
if (angle > 250*proportion)
angle = 250*proportion;
if (angle < 0)
angle = 0;
Animation anim =new RotateAnimation(lastTemp, angle, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setFillAfter(true); // 设置保持动画最后的状态
anim.setDuration(500); // 设置动画时间
anim.setInterpolator(new AccelerateDecelerateInterpolator()); // 设置插入器
ivPointer.startAnimation(anim);
lastTemp = angle;
}