1

是否有可能按照谷歌指南的建议实施副标题行为(参见:https ://www.google.com/design/spec/components/subheaders.html )?特别是标题的粘性功能对我来说很重要。

我在 github 上找到了不同的库(例如https://github.com/emilsjolander/StickyListHeaders),但我想知道 android sdk 中是否有直接支持。

谢谢

4

1 回答 1

1

If you don't want them sticky, and exactly know what positions the headers are going to be( in your data array), then you could simply use following trick :

header is just another list item type,

so extend BaseAdapter and override following methods :

@Override
getViewTypeCount(){
    return 2;// 1(list items) + 1(for header)
}

@Override
getItemViewType(int position){
if(want to show header at position)
    return 1; // header item
else
    return 0;// regular items
}

@Override
getView(int pos,....)
{
    if(getItemViewType(pos)==0){// regular item
        inflate/reuse convertView; // cast to regular item & bind data
    } else {
        inflate/reuse convertView; // cast to hdr view and bind data 
    }
    return convertView;
}

for detailed analysis you could follow this link : http://cyrilmottier.com/2011/07/05/listview-tips-tricks-2-section-your-listview/

于 2015-10-27T18:33:00.573 回答