Android 随着速度的变化,围绕其中心旋转速度计针规

Android 随着速度的变化,围绕其中心旋转速度计针规,android,center,angle,image-rotation,Android,Center,Angle,Image Rotation,大家好 我编写了一个应用程序,其中我有一个速度计,指针垂直设置为90度,我试图以每秒变化的速度围绕其中心旋转指针(我在文本视图中显示速度,从0到120随机变化) 我从远程服务获取速度并显示在文本视图中 因此,当速度变化时,车速表针形仪表应围绕其中心相应变化。我的意思是,如果速度是30,指针应该是30,以此类推 我的代码不能正常工作,如何解决这个问题 感谢你的帮助 这是我的密码: pointer1 = (ImageView) findViewById(R.id.pointer1); double

大家好

我编写了一个应用程序,其中我有一个速度计,指针垂直设置为90度,我试图以每秒变化的速度围绕其中心旋转指针(我在文本视图中显示速度,从0到120随机变化)

我从远程服务获取速度并显示在文本视图中

因此,当速度变化时,车速表针形仪表应围绕其中心相应变化。我的意思是,如果速度是30,指针应该是30,以此类推

我的代码不能正常工作,如何解决这个问题

感谢你的帮助

这是我的密码:

pointer1 = (ImageView) findViewById(R.id.pointer1);

double degrees= speed;
double angle = degrees * 2 * Math.PI / 360.0;

for( speed=0;speed<120;speed++){
    RotateAnimation rAnimAntiClockWise = new RotateAnimation(180-0.0f, 180-speed,
        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

    rAnimAntiClockWise.setInterpolator(new LinearInterpolator());
    rAnimAntiClockWise.setDuration(100);
    rAnimAntiClockWise.setFillAfter(true);
    rAnimAntiClockWise.setDuration(10000);
    rAnimAntiClockWise.setRepeatCount(-1);
    rAnimAntiClockWise.setRepeatMode(2);
    pointer1.startAnimation(rAnimAntiClockWise); 
}

private void invokeService() {
    if (conn == null) {

    } else {
        try {
        System.out.println(remoteService);

        int speed = remoteService.getSpeed();

        System.out.println("myspeed" + speed);

        TextView r = (TextView) findViewById(R.id.text2);
        r.setText("" + Integer.toString(speed));
            Log.d(getClass().getSimpleName(), "invokeService()");

        } catch (RemoteException re) {
        Log.e(getClass().getSimpleName(), "RemoteException");
        }
    }
}
pointer1=(ImageView)findViewById(R.id.pointer1);
双度=速度;
双角度=度*2*Math.PI/360.0;
对于(速度=0;速度请尝试以下代码:

currentDegree=60;
speedDisplayTxt.addTextChangedListener(new TextWatcher()
    {

        public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
            fromDegrees= currentDegree;
            String speed=txt.getText().toString();
            toDegree= //convert speed to angle here.
            RotateAnimation NeedleDeflection = new RotateAnimation(fromDegrees, toDegrees, ...){
            protected void applyTransformation(float interpolatedTime,Transformation t) {
                float currentDegree = fromDegrees+(toDegrees-fromDegrees)*interpolatedTime;
                super.applyTransformation(interpolatedTime, t);
                };
            NeedleDeflection.setDuration(duration); 
            NeedleDeflection.setFillAfter(true);
            needle.startAnimation(NeedleDeflection);

                  }
             }          

    }

  });
请尝试以下代码:

currentDegree=60;
speedDisplayTxt.addTextChangedListener(new TextWatcher()
    {

        public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
            fromDegrees= currentDegree;
            String speed=txt.getText().toString();
            toDegree= //convert speed to angle here.
            RotateAnimation NeedleDeflection = new RotateAnimation(fromDegrees, toDegrees, ...){
            protected void applyTransformation(float interpolatedTime,Transformation t) {
                float currentDegree = fromDegrees+(toDegrees-fromDegrees)*interpolatedTime;
                super.applyTransformation(interpolatedTime, t);
                };
            NeedleDeflection.setDuration(duration); 
            NeedleDeflection.setFillAfter(true);
            needle.startAnimation(NeedleDeflection);

                  }
             }          

    }

  });

我的代码没有完全工作>它在做什么?你的错误是什么?@Anders Metnik,没有错误,但它以逆时针方向无限旋转90到45度是有意义的,这似乎也是你在代码中要求它做的事情?嗯,但它应该随着速度的变化而变化如果spped是120,那么指针应该在120,我必须根据速度设置针规的角度。因为我是android新手,所以我做不到。我做了很多尝试,但没有结果。我Raghav你检查过这个示例了吗?我的代码没有完全工作>它在做什么?你的错误是什么?@Anders Metnik,没有错误,但是它以逆时针方向无限旋转90到45度这似乎也是你在代码中要求它做的事情?嗯,但它应该根据速度的变化而变化如果spped是120,那么指针应该是120,我必须根据速度设置针规的角度。因为我是android新手,所以我做不到。我试了很多次,但没有结果我拉格哈夫你检查过这个例子吗示例@subbarddy PolamReddy,我有速度计算值,但如何将这些速度值设置为带指针的速度计…请将
RotateAnimation
应用于指针。参考:@subbarddy PolamReddy,查看@subbarddy PolamReddy,我有速度计算值,但如何将这些速度值设置为带指针的速度计。。.plzApply
RotateAnimation
针。参考:@subbarddy PolamReddy,查看