Remove header from listView

前端 未结 7 2091
执念已碎
执念已碎 2021-02-01 04:58

I\'m having some problems when trying to remove the header from a listView. At first I use addHeaderView() to add it, but when I change to another layo

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-01 05:40

    I encountered this problem in a slightly disguised scenario: the ListView I was dealing with came from PreferenceFragment, and the header represents a PreferenceCategory. So, my freedom of setting up the ListView was severely limited. But there were two approaches (partly inspired by other answers on this page). One was to add a custom layout to my PreferenceCategory (using a class that extends android.preference.PreferenceCategory, see Custom PreferenceCategory Headings). But I found an easier workaround: for the first Preference in this PreferenceCategory, I override onCreateView():

    @Override public View onCreateView(ViewGroup parent) {
        parent.setTop(-parent.getChildAt(0).getTop());
        return super.onCreateView(parent);
    }
    

提交回复
热议问题