1

I want to set up a slider bar in my Android application, but with very fine control. I have the following code to define bar and its range:

skBar = new SeekBar (this);
skBar.setBackgroundColor (TRANS_BLUE);
skBar.setMax (2000);
skBar.setMinimumHeight (20);
skBar.setProgress (origOffset);

I'm setting the bar up programmatically, because I need the application to continue working while the user adjusts it, but I really don't think that's the problem. The problem is that the slider seems to be moving in increments of at least 10. Obviously, I could very well be bumping up against limitations of the hardware (I'm using a Nexus 7), but I'm not sure of that. Is there something I need to add to address fine granularity??

Rich
  • 4,157
  • 5
  • 33
  • 45

1 Answers1

1

I can see one of two things causing this problem.

  • If your SeekBar width is too small in relationship to your max value. For example, if your seekbar is only 500 pixels wide, and the max is 2000, the absolute minimum value change you can get is 2000 / 500 = 4. That's for a 1 pixel movement. You probably can't get a one-pixel movement, though, due to the below reason.

  • Even with a large SeekBar, you're going to hit a problem with touch slop. To prevent flooding the system with touch events, there's a threshold. If the movement is too small, the system simply throws it out. Values for this vary from device to device, so I can't tell you what it is on a Nexus 7. I've seen values as small as 4 and as large as 12, personally.

To figure out what your touch slop is, you can use ViewConfiguration#getScaledTouchSlop(), and you can read more about it in general in this fine answer.

So, assuming an average touch slop of 8, even with a rather large SeekBar of 1200 pixels(and your original max of 2000), you should get a minimum value change of: (2000 / 1200) * 8 = 13.333....


There's not much you can do to address the touch issue, but if you're willing to add forward/next controls to your seekbar, you can simply update the progress yourself using whatever increment you want. This would be good for fine control, while the touch movement would be for coarse.

Community
  • 1
  • 1
Geobits
  • 22,218
  • 6
  • 59
  • 103
  • I'm pretty sure this is what I'm seeing. Even though this application is specific to a Nexus 7 (with about 1000 horizontal pixels in Landscape orientation), it appears I'm simply demanding more than the hardware can provide. Thanks for the extra eyes on the problem. – Rich Jul 30 '13 at 15:09