0

I have a canvas with scrollbars (not using ScrollView), and I need to know the measures of the scrollbars, i.e width and height. Is there any way to determine them? Thanks.

user940016
  • 2,878
  • 7
  • 35
  • 56
  • Well if you're using a canvas, you need a reference to whatever object you're trying to draw. Shouldn't you be able to calculate the width/height from that object since you need coordinates to draw it from? – Cruceo Jun 12 '12 at 21:39
  • The scrollbars are attached to the canvas automatically. I don't have their coordinates. – user940016 Jun 12 '12 at 21:44
  • And you don't have some kind of reference to the scrollbar object? – Cruceo Jun 12 '12 at 21:48
  • No, because it's built-in and handled automatically. – user940016 Jun 13 '12 at 13:06

1 Answers1

1

You can use View.getScrollbarSize(). It will return the width of vertical scrollbars or the height of horizontal scrollbars.

Romain Guy
  • 97,993
  • 18
  • 219
  • 200
  • There is no such function! The API lists the scrollBarSize XML attribute, but it has no related methods! – user940016 Jun 13 '12 at 13:05
  • My bad you're right, we're adding it to the next release of Android. Another way to do it then is to use ViewConfiguration. It has a method to get the default scrollbar size. – Romain Guy Jun 13 '12 at 17:54
  • Sets the width of vertical scrollbars and height of horizontal scrollbars. Which is what I want, but the getScaledScrollBarSize function reads: The width of the horizontal scrollbar and the height of the vertical scrollbar. Which is not what I need, because I want to know how much space they occupy. Is it an error in the documentation? (which is probable since the width of horizontal scrollbar and the height of the vertical one are not necessarily the same) – user940016 Jun 15 '12 at 13:41