如何在recyclerview中实现粘性行

时间:2015-09-16 12:41:02

标签: java android

我正在实施排名视图。

我想突出显示并将当前用户的行保持为始终可见的粘性行。

如果用户在行下滚动,则将行设置为列表标题;如果用户滚动,则将行设置为页脚

如何使用RecyclerView

进行操作

1 个答案:

答案 0 :(得分:-3)

您可以使用ViewType的帮助。

 @Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    if (viewType == TYPE_ITEM) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.scheduler_settings_days_row, parent, false);
        return new ViewHolderItems(v);
    } else if (viewType == TYPE_HEADER) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.scheduler_settings_days_row_header, parent, false);
        return new ViewHolderHeader(v);
    } else if (viewType == TYPE_FOOTER) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.scheduler_settings_days_row_footer, parent, false);
        return new ViewHolderFooter(v);
    } else {
        return null;
    }
    //throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly");
}

   @Override
public int getItemViewType(int position) {
    if (isPositionHeader(position)) {
        return TYPE_HEADER;
    } else {
        return TYPE_ITEM;
    }

 private boolean isPositionHeader(int position) {
    return position == 0;
}