I have implemented a custom Layout that extends RelativeLayout. It displays lots of different elements that are created at run-time and is scrollable in both dimensions usin
Just had this same problem and finally figured it out.
The "problem" is that you are extending RelativeLayout
, which is a subclass of ViewGroup
. I found that I had no problem doing what you described in your question to get a custom View
to display scrollbars, but when I extended ViewGroup
or one of its subclasses, no scrollbars appeared.
I finally remembered that ViewGroup
s, by default, don't draw themselves. I added one line to my custom ViewGroup
constructor:
setWillNotDraw(false);
What do you know, the scrollbars appeared!
Hope that helps.
Fyi, on Android 3.2/Google TV, and Android 3.2.1/Tablet, the <declare-styleable/> part of the solution is not optional when extending ViewGroup. The problem seems to be that none of the scrollbar drawables and sizes used by View to draw the scrollbars are loaded unless all of the corresponding scrollbar properties in the <declare-styleable/> are set. Failing to set some significant number of those properties results in a null pointer exception during layout on 3.2. I also suspect that the GridView/ListView/AbsListView/AdapterView series of classes don't set the horizontal scrollbar attributes, if that's what you happen to be chasing.
The general steps seem to be:
I think that's it. Chances of all that working on Android 6.0... slim to none. :-/