0

I have read a number of literatures that say not to do this. But they have yet to offer an alternative solution. The question seems to come up a lot, though. Here is my problem.

  • I want my main layout to be scrollable (this is because it will have more views than can fit the screen). My main layout is a vertical LinearLayout. So for now I have it inside a ScrollView.

  • one of the many children of my LinearLayout is a ListView (shows 3 items, user scrolls the ListView for more).

  • You can image the other children of my LinearLayout to be whatever will convince you that I need this to work: for example, one may be a scrollable horizontal LinearLayout; another may be a ViewPater; etc.

Now if the content of my LinearLayout could all fit the screen at once, I would have no problem. But I have about six different children in my LinearLayout and only about three are visible at one time. So, yes, I do need to be able to scroll my LinearLayout.

One more thing. If I am scrolling the child ListView and I reach the end, I need the parent LinearLayout to resume control and start scrolling as user scrolls.

CLARIFICATION

One clarification is that my ListView is actually dynamically added to a ViewPager. So technically, a ViewPager is the child of my LinearLayout. But then inside the ViewPager, one of the pages is a ListView.

NOTE

By the way, I have read scrolling ListView within ScrollView. The answer there is good, but I still have a few problems.

  • once edge of ListView is reached control does not revert to ScrollView

  • If any of the other child views of the LinearLayout have a click listener, then I cannot use them to scroll the ScrollView. So basically for most of the screen, the scroll view is not scrollable.

Community
  • 1
  • 1
learner
  • 11,490
  • 26
  • 97
  • 169
  • 2
    looks like a valid question to me. So I am not sure why one person downvoted. Please provide comments instead of simple cheap downvotes. – Konsol Labapen Nov 29 '13 at 15:41
  • Honestly, this sounds like it would be a nightmare for users. Scrolling within a scrollable window is something users would find difficult, which is why apps don't generally do it. Instead consider selecting an item to open another activity or fragment or popup. Think about how configuration activities are usually arranged when one config item can open up a set of other options. If you look at fragments, you could then cater for larger screens too. – Nibor Nov 29 '13 at 15:42
  • Actually it's not. But I see how it may sound that way. I have played around with the mockup from the designer, and it looks and works pretty well. – learner Nov 29 '13 at 15:44
  • Also the iOS version of the app is already created (stealth mode) and the design works fine. – learner Nov 29 '13 at 20:07

1 Answers1

0

You could use the ListView as main layout (instead of the ScrollView) and put the views on top with the lists addHeaderView()-method (grouped in a LinearLayout or something like that) and do the same with the items below the list, with the addFooterView-method of the ListView.

I did not test it, but I think it might work.

Habizzle
  • 2,971
  • 3
  • 20
  • 23
  • But the ListView used in the design is added dynamically to a ViewPager. Understand this: The layout actually has no ListView; it has a ScrollView that contains a LinearLayout, which in turn comprises a number of child views none of which is a ListView. But then programmatically, one of the child views, a ViewPager, takes a ListView in one of its pages. That's when the problems start. So in your design, everything except the ViewPager would to to HeaderView or FooterView. But I don't see what I gain by placing the single ViewPager as the item of a ListView. – learner Dec 03 '13 at 14:42