tags:

views:

58

answers:

2

Here's the scenario conceptually (excluding linearlayouts)

ScrollView
  Button
  Checkboxes
  Spinner
  ListView (full-size, non-scrolling)
AdMob advert

i.e. a scrolling pane, which has a filtering UI at the top, followed by results, but the advert must always remain visible, and when scrolling down the filter UI must scroll away, leaving maximum space for results.

I'm aware there are issues with a ListView inside a ScrollView, though for me it is working well in many ways (I'm fixing the length of the ListView to stop it collapsing). So the screen scrolls nicely, the ad stays put at the bottom, and it looks good.

But the problem I'm seeing is, inexplicably, when the activity opens, the ScrollView is scrolled down a bit, so the ListView is at the top of the screen. I assume this is a default behaviour, so I set about trying to force the scroll position of the ScrollView to the top, but I've tried various methods, and see no effect:

scrollview.scrollTo(0, 1000/-1000);
scrollview.smoothScrollBy(0, 1000/-1000);
scrollview.fullScroll(View.FOCUS_UP);

Is there any way to force the ScrollView to start with the scroll position at the top?

If not, how can I have an ad that doesn't scroll off the bottom, but a filter UI that always scrolls off the top? Using ListView seems overkill as I don't need scrolling but it does provide many benefits so would be nice to avoid starting from scratch and rendering everything myself.

A: 

Why are you using a listview if you're not scrolling? Why can't you just use a linearlayout or something more fit to this situation? You mention a filter, you could very easily roll your own filter especially since apparently you just have a few items in your listview.

Falmarri
I'm filling the ListView from an adapter, and I can't do that with a LinearLayout. The items in the ListView are dynamic, and I'd certainly be very interested to know what would work better as a replacement for the ListView, so I solve the scrolling issue, but retain benefits of the ListView, like data binding and item reuse. Would it makes sense to replace the ListView with an AdapterView?
Ollie C
You can create an adapter and just not bind it to a listview
Falmarri
What would I bind it to?
Ollie C
I'm not sure if other views are able to "bind" to adapters. But you could write your own LinearLayout in java that watches for changes in the adapter. I'll bet if you look at the implementation of `ListView.setAdapter()` it would be fairly simple
Falmarri
If I have to do that then I will, but isn't there a standard component that lets me create a set of consecutive items in a non-scrolling list? Android seems pretty bad sometimes for what would be pretty easy on other platforms :-( This UI pattern is very common.
Ollie C
Well an adapter will do that just fine. Just create a linearlayout and then you can call adapter.getView() yourself and add those views to your linearlayout. That's all binding it to a listview does anyway.
Falmarri
A: 

Use something other that a ListView, you can dinamically generate linearLayouts to show the data you want. You should never use a listview inside a scrollView, it doesnt work for a simple reason, when you scroll, what should scroll, the listview or the scroll view. A couple of people from google have stated not to do this.

blindstuff
Sure, I understand using a scrolling control inside a scrolling control is bad news (from a UI perspective, let alone the implementation) but in a scenario where the ListView has no scrollbars, this limitations makes less sense.
Ollie C
How are you guaranteeing that the listview doesn't scroll?
Falmarri
The fact that is doesnt scroll indicates that there isnt much data to show, that was my main reasoning for thinking that he should need a list view.
blindstuff
I've forced the length of the ListView using android:layout_height, which ensures it never has a scrollbar. So in my app there is only ONE scrollbar, that on the ScrollView. So it actually works very well, apart from this issue where the ScrollView position is being affected by the ListView's presence. What class would make a good replacement for the ListView, where I can use an adapter, but avoid all the scrolling issues?
Ollie C