旋转速度计针规围绕它的速度改变中心 [英] Rotating speedometer needle gauge around its center as the speed changes

查看:186
本文介绍了旋转速度计针规围绕它的速度改变中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经写了一个应用程序,我有一个针头垂直设定为90度,我想绕其与对于每一秒的变化(我在显示速度在文本的速度心针测速仪认为随机变化从0到120)

我收到的速度从一个远程服务,并显示在一个TextView。

这样的速度改变里程表针距应相应地改变绕其中心。我的意思是如果速度是30针应该是30,因此在速度表。

我的code工作不完全是,如何解决这个问题?

帮助总是AP preciated,谢谢你。

下面是我的code:

 指针1 =(ImageView的)findViewById(R.id.pointer1);

双学位=速度;
双角=度* 2 * Math.PI / 360.0;

对于(速度= 0;速度< 120;速度++){
    RotateAnimation rAnimAntiClockWise =新RotateAnimation(180-0.0f,180的速度,
        Animation.RELATIVE_TO_SELF,0.5F,Animation.RELATIVE_TO_SELF,0.5F);

    rAnimAntiClockWise.setInterpolator(新LinearInterpolator());
    rAnimAntiClockWise.setDuration(100);
    rAnimAntiClockWise.setFillAfter(真正的);
    rAnimAntiClockWise.setDuration(10000);
    rAnimAntiClockWise.setRepeatCount(-1);
    rAnimAntiClockWise.setRepeatMode(2);
    pointer1.startAnimation(rAnimAntiClockWise);
}

私人无效invokeService(){
    如果(康涅狄格州== NULL){

    } 其他 {
        尝试 {
        的System.out.println(remoteService);

        INT速度= remoteService.getSpeed​​();

        的System.out.println(myspeed的+速度);

        TextView中R =(TextView中)findViewById(R.id.text2);
        r.setText(+ Integer.toString(速度));
            Log.d(的getClass()getSimpleName(),invokeService()。);

        }赶上(RemoteException的重){
        Log.e(的getClass()getSimpleName(),RemoteException的。);
        }
    }
}
 

解决方案

试试这个code:

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

        公共无效onTextChanged(CharSequence的arg0中,诠释ARG1,INT ARG2,
                INT ARG3){
            fromDegrees = currentDegree;
            字符串速度= txt.getText()的toString()。
            toDegree = //转换速度,角度位置。
            RotateAnimation NeedleDeflection =新RotateAnimation(fromDegrees,toDegrees,...){
            保护无效applyTransformation(浮动interpolatedTime,变换T){
                浮currentDegree = fromDegrees +(toDegrees-fromDegrees)* interpolatedTime;
                super.applyTransformation(interpolatedTime,T);
                };
            NeedleDeflection.setDuration(持续时间);
            NeedleDeflection.setFillAfter(真正的);
            needle.startAnimation(NeedleDeflection);

                  }
             }

    }

  });
 

Hi all,

I have written an application where I have a speedometer with a needle vertically set at 90 degree and I am trying to rotate the needle around its center with the speed that changes for every one second(I am displaying the speed in a text view that changes randomly from 0 to 120)

I am getting the speed from a remote service and displaying in a textview.

so as the speed changes the speedometer needle gauge should change accordingly around its center. I mean If speed is 30 the needle should be at 30 and so on in speedometer.

My code is not working exactly, How to get around this problem?

Help is always appreciated,Thanks.

Here is my code:

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");
        }
    }
}

解决方案

Try this code:

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);

                  }
             }          

    }

  });

这篇关于旋转速度计针规围绕它的速度改变中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆