android中的速度表

时间:2014-05-19 13:03:50

标签: android angle

我想在android中制作速度计..想法在imageView上只是简单点击第二个imageView将旋转45度。但问题是第二个imageView不能在固定点周围旋转....任何人都可以建议我做什么

public class BloodPressureActivity extends Activity {

ImageButton btnImgBoy;
ImageView imgVNeddleBoy;
private int currentAngle = 0;
private int numOfAngle = 7;
Animation anim, zoomAnim;

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_blood_pressure);
    btnImgBoy = (ImageButton) findViewById(R.id.imageButtonBollenBoy);
    imgVNeddleBoy = (ImageView) findViewById(R.id.imageViewNeddlBoy);
    anim = AnimationUtils.loadAnimation(this, R.anim.back_rotation);
    zoomAnim = AnimationUtils.loadAnimation(this, R.anim.zoom_anim);
    // anim.setFillAfter(true);

    btnImgBoy.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // rotate image view neddle
            btnImgBoy.startAnimation(zoomAnim);
            currentAngle++;
            currentAngle = currentAngle % numOfAngle;
            switch (currentAngle) {
            case 0:
                imgVNeddleBoy.setRotation(45);
                break;
            case 1:
                imgVNeddleBoy.setRotation(90);
                break;
            case 2:
                imgVNeddleBoy.setRotation(135);
                break;
            case 3:
                imgVNeddleBoy.setRotation(180);
                break;
            case 4:
                imgVNeddleBoy.setRotation(225);
                break;
            case 5:
                imgVNeddleBoy.setRotation(270);
                break;
            case 6:
                imgVNeddleBoy.setRotation(315);
                imgVNeddleBoy.startAnimation(anim);

                break;

            }

        }
    });
}

}

1 个答案:

答案 0 :(得分:0)

使用setPivotXsetPivotY设置旋转中心。这也是规模的中心。