0

I have a ScrollView that I would like to have a variable number of children in. Easy game, use LinearLayout.

Now, I am looking for a way to make the widths of the children some proportion of the ScrollView itself (it is going to be placed in another auto-laid out view).

I have tried using LinearLayout weights (and weightSum) to keep them proportional to themselves, but then they just fill the ScrollView and don't allow scrolling.

I have android:fillViewport="true" set on the ScrollView so that it fills its container, but I can't seem to find a way to make the children some fraction of the ScrollView itself.

Basically I want ALL the children to have a fixed width of say a 3rd of the available space, so that while scrolling at most 3 items are shown, and they are proportional to the available space.

My thoughts are that I will need to create a CustomScrollView that extends ScrollView, and then @Override the onMeasure() method, is this the way, or is there an easier, more elegant solution (hopefully using the layout_weights engine already in LinearLayout)?

Any help would be much appreciated!

P.S. I had a beautiful picture drawn, but apparently you need 10 rep, lame to the n^th degree. I would love to have contributed to more questions on SO, but I need like 15 rep to vote up a question that helped me? That means I need to ask 15 questions, of which I can already find all the answers on here.

logan
  • 430
  • 5
  • 11
  • Have you tried a GridView? Otherwise you'd have to use nested vertical/horizontal LinearLayouts and manually map the data to them at runtime using weights or percentages of the DisplayMetrics' width – Cruceo Apr 15 '14 at 17:38
  • Hi, thanks for the reply, I had not tried GridView, and got excited for a minute. Unfortunately it does not support horizontal scrolling, some [people](http://stackoverflow.com/questions/13236123/how-to-make-grid-view-horizontally-scrollable-in-android) have suggested using a Gallery, but as I understand it that has been deprecated as of API level 16, and the suggested replacement is a HorizontalScrollView. – logan Apr 16 '14 at 08:24

0 Answers0