1

For example I if I move seekbar to 100, I want imageView to rotate to 100deg within one second. The problem is if I move it right away to 50 it jumps to 100 and goes slowly to 50. Is there a way to rotate it from current position... or maybe more elegant solution for smoother animation for those random degrees?

seekBar1 = (SeekBar) findViewById(R.id.seekBar1);
arrow2 = (ImageView) findViewById(R.id.imageView1 );    

seekBar1.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
{
    public void onProgressChanged(SeekBar seekBar1, int progress, boolean fromUser)
    {
        currentSpeed.setText(""+progress);

        RotateAnimation rotateAnimation = new RotateAnimation(fromPosition ,progress,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
                rotateAnimation.setInterpolator(new LinearInterpolator());
                rotateAnimation.setDuration(1000);
                rotateAnimation.setFillAfter(true);
                arrow2.startAnimation(rotateAnimation);
        fromPosition=progress;                  
    }
        public void onStartTrackingTouch(SeekBar seekSize1) {}
        public void onStopTrackingTouch(SeekBar seekSize1) {}
});
koopajah
  • 23,792
  • 9
  • 78
  • 104
Daniel
  • 1,064
  • 2
  • 13
  • 30

1 Answers1

0

I know this question was posted quite some time ago - but I had struggled with the same issue and came up with a solution. You have to use what is called a low-pass filter. This filters out some of the noise, and the "outlier" values that come back from the sensor. Take a look at this.

Community
  • 1
  • 1
jiiri
  • 330
  • 1
  • 12