2

I've got the following node in my XML layout:

<com.x.y.view.TagLayout android:id="@+id/TagLayout" 
android:layout_width="fill_parent" android:layout_height="170dip" />

TagLayout is a class that extends ViewGroup, and basically holds a bunch of buttons with text (a custom object that act as tags, but that's neither here or there).

The problem is that when there are too many buttons, the view no longer scrolls. I can confirm that I am adding tags but I can't see anything.

If I wrap the above within a ScrollView, the layout never renders. I tried adding the attributes android:isScrollContainer and android:scrollbars, but that doesn't change anything. Is there something I'm missing here?

I should also add that TagLayout is overriding the onMeasure() event. I guess I need to implement a scrolling mechanism there...?

2 Answers2

1

Well, I mostly got it. I had to actually wrap the node above with a LinearLayout, then wrap THAT around a ScrollView. The padding is a little off (the last item is cut from the view) but it's on the right track.

  • 1
    Please share your code if possible. I would like to take a look since I am facing same problem.. THanks if you could do so. Thanks in advance – user1169079 Mar 19 '12 at 05:56
1

You can add scrolling to your custom ViewGroup without wrapping it in multiple other layouts and views (in fact, it's better not to wrap it if you don't have to...having flat layout hierarchies is much better for performance). Just do everything described in this question, and make sure you add setWillNotDraw(false); to your custom ViewGroup constructor as described in this answer.

Community
  • 1
  • 1
ashughes
  • 7,155
  • 9
  • 48
  • 54