Skip to main content

Introducing SuperSLiM

StickyGridHeaders is dead, long live SuperSLiM!

GitHub Project Page

After a road accident that prevented me from working for a while, I finally got around to rewriting StickyGridHeaders. However, this rewrite completely changed everything, so I have started a new project called SuperSLiM, and all development will be focused there.

SuperSLiM

SuperSLiM is a library that provides a layout manager for RecyclerView and allows you to create vertical lists with per section headers and layouts.

Section Layouts  

SuperSLiM also lets you lay out data sections in different ways. This is something that just wasn't possible with ListView or GridView. Anyway, with SuperSLiM you just create a factory that provides layouts for each section on demand. Put that in the layout manager and you are good to go.

Headers 

There are a number of different kinds of section headers you can use in SuperSLiM. 

Sticky headers
These always display when some part of the associated section is visible. This has the effect that, as you scroll the list to the end, the section headers scroll up and stick to the top of the screen as long as the section is still partly visible. 

Margin headers
These are headers that display in the start, or end margins of the section (left and right margins). The header's top is aligned with the section's top, and the header can also be optionally sticky. 

Overlay headers
An overlay header is drawn over the top of the section content. They can also be optionally sticky.
Headers are set on a per section basis using layout parameters, or XML attributes on the header view bound by your Adapter.
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          app:slm_isHeader="true"
          app:slm_isSticky="true"
          app:slm_headerStartMargin="56dip"
          app:slm_alignHeader="start"
          android:gravity="start"
          android:padding="16dip"
          android:textSize="24sp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
The biggest difference with the API from a standard Adapter is that you have to tell SuperSLiM two details about your sections. What is the first item in each section, and to which section does the item belong. However, doing this is trivial and can be easily done in your onBindViewHolder method.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    final LineItem item = mItems.get(position);
    holder.bindItem(item.text);
    final LayoutParams params = (LayoutParams) holder.itemView.getLayoutParams();
    params.section = item.section;
    params.sectionFirstPosition = item.sectionFirstPosition;
    holder.itemView.setLayoutParams(params);
}


Comments

  1. I am sorry to say this but you wrote a lot of things about your library only to confuse us. why don't you just write on single article with a very easy example but covering all the basic steps.

    I just saw your library and was trying to test it but it is not fully documented. I expect your library is very nice but your tutorials, blog post, and Trello stuff doesn't help for new people coming to your library.

    ReplyDelete

Post a Comment