How can I get my ListView to scroll?

后端 未结 4 957
梦谈多话
梦谈多话 2020-12-09 05:32

I have a quite complex View build-up, and as a part of that, I have a ListView inside a LinearLayout within a ScrollView (and quite a lot more components, but they do not ma

4条回答
  •  难免孤独
    2020-12-09 05:54

    Instead of ListView with other layouts inside ScrollView create one ListView with header and footer.

    Add views that should be above ListView as a header:

    addHeaderView(View v)
    

    and that below as a footer:

    addFooterView(View v)
    

    Put everything what should be above ListView to header of ListView and the same with footer.

        LayoutInflater inflater = LayoutInflater.from(this);
        mTop    = inflater.inflate(R.layout.view_top, null);
        mBottom = inflater.inflate(R.layout.view_bottom, null);
    
        list.addHeaderView(mTop);
        list.addFooterView(mBottom);
        // add header and footer before setting adapter
        list.setAdapter(mAdapter);
    

    In result you'll get one scrollable view.

提交回复
热议问题