Search code examples
androidscrollviewandroid-custom-view

How to implement Custom ScrollView Like listview?


I want to add my Listview in another scroll view but when i add it in scrollview in xml it show only one item.so i want to create custom scroll view so i can put it in another scrollview.


Solution

  • Things to take into account:

    • ScrollView can only have a single child. If you want to add more of them you have to put them inside another ViewGroup, then add it to the ScrollView.
    • ListView handles its own scrolling, you should never put it inside another ScrollView.

    If what you need is to have a certain number elements, a list of items included, scroll together as a single entity, you have two options:

    • Do not use a ListView, but a vertical LinearLayout. It will work, but with this all your rows will be created at once and won't be recycled while scrolling, so you should only do this if you can be sure your list will have a limited number of items.
    • A better option is to use a ListView as your main ViewGroup and add to it every other element you need in the scroll as headers or footers.