0

I would like a scrollview where new items are automatically put on top of the old items and the scrollview grows vertically up. Is this possible?

Robert Harvey
  • 168,684
  • 43
  • 314
  • 475
TrolliOlli
  • 807
  • 1
  • 7
  • 16
  • Anything is possible given enough time, money and computing resources. – Robert Harvey Jul 01 '13 at 17:46
  • Any idea how to do it? I would have thought android would have some sort of gravity feature for scrollviews to make this easily possible. But I can't find it anywhere. Is this something I'll have to build myself? – TrolliOlli Jul 01 '13 at 17:49
  • Can you use a ListView and add items to the top as described here? http://stackoverflow.com/questions/15597450/androd-listview-add-items-to-top-without-list-view-scroll – Robert Harvey Jul 01 '13 at 17:50
  • I may actually just be able to use a ListView with: stackFromBottom = "true". – TrolliOlli Jul 01 '13 at 18:02
  • Honestly I never knew I was supposed to. I googled how to do so and will go back through and accept answers. Thanks! – TrolliOlli Jul 01 '13 at 18:12

2 Answers2

1

ScrollView extends FrameLayout, which in turn extends ViewGroup. To add a child view to a ViewGroup, look at the api here. It would look something like this:

scroll.addView (childView, 0) 

EDIT: This question is very similar to your's. The easiest solution posted there is to add fillViewPort="true" to your ScrollView. Afterwards, for each Button you need to set the attribute to android:layout_alignBottomParent="true"

Community
  • 1
  • 1
jkau
  • 464
  • 4
  • 12
  • I guess I wasn't really clear in my original question. My biggest concern is having the items automatically start at the bottom of the view. This scrollview is going to hold a varying number of buttons and I want the buttons to start at the bottom of the screen. Currently, my scrollview always pushes buttons to the top of the screen. – TrolliOlli Jul 01 '13 at 18:20
  • From what I understand, you have a varying number of buttons in a scrollview that takes up the entire screen correct? Are you having anything on top of the buttons in the ScrollView? – jkau Jul 01 '13 at 18:25
  • You are correct. My scrollview acts as a toolbar that extends the entire length of the screen. I will always have a set of original buttons, but I may add more buttons depending on other characteristics. Since it's a toolbar, I want it to start at the bottom of the screen as this is closer to the user's hands. The toolbar/scrollview will only ever have buttons. Nothing else on top of it. Edit For further clarification. I can get this to work perfectly using a linear layout with gravity set to "bottom". This won't allow scrolling once I add buttons past the edge of the screen though. – TrolliOlli Jul 01 '13 at 18:28
1

Not sure and I don't have a system here to test it but like jkau wrote

scroll.addView (childView, 0);

and

scroll.fullScroll(ScrollView.FOCUS_UP);

should do the trick. And you really should accept answers or write why you are not happy with the answer

JackZ
  • 80
  • 8
  • fullScroll() all the way to the top would only be useful if there was some sort of space between the top of the ScrollView and the first button. The way he clarified the question also seems to indicate he wants something other than what I suggested with addView() – jkau Jul 01 '13 at 18:28