Android list view inside a scroll view

后端 未结 30 2068
一向
一向 2020-11-21 13:43

I have an android layout which has a scrollView with a number of elements with in it. At the bottom of the scrollView I have a listView

30条回答
  •  不知归路
    2020-11-21 13:58

    The answer is simple and I am surprised it has yet to be answered here.

    Use a Header View or/and Footer View on the list itself. Don't mix a ScrollView with a ListView or anything that can scroll. It's meant to be used with headers and footers :)

    Essentially, take all the content above your ListView, put it in another .xml file as a layout and then in code inflate it and add it to the list as a header view.

    i.e.

    View header = getLayoutInflater().inflate(R.layout.header, null);
    View footer = getLayoutInflater().inflate(R.layout.footer, null);
    listView.addHeaderView(header);
    listView.addFooterView(footer);
    

提交回复
热议问题