Android ListView with fixed header and footer

前端 未结 7 909
半阙折子戏
半阙折子戏 2020-12-30 07:14

How can I create a ListView with fixed header and footer?

I don\'t want the header/footer to scroll with the items in the ListView.

7条回答
  •  长发绾君心
    2020-12-30 07:44

    create your custom header and footer with your list view code as below

    header.xml file

     
    
            
    
        
    

    footer.xml file

     
            

    add where your listview

     LayoutInflater inflaterHeader = getLayoutInflater();
        ViewGroup header = (ViewGroup) inflaterFooter.inflate(
                        R.layout.header, list_view, false);
        yourListView.addHeaderView(header);
    
        LayoutInflater inflaterFooter = getLayoutInflater();
                ViewGroup footer = (ViewGroup) inflaterFooter.inflate(
                        R.layout.footer, list_view, false);
        yourListView.addFooterView(footer);
    

提交回复
热议问题