RecyclerView.canScrollVertically(1)false表示已经滚动到底部
RecyclerView.canScrollVertically(-1)false表示已经滚动到顶部
/**
* RecyclerView 移动到当前位置,
*
* @param manager 设置RecyclerView对应的manager
* @param n 要跳转的位置
*/
public static void MoveToPosition(LinearLayoutManager manager, int n) {
manager.scrollToPositionWithOffset(n, 0);
manager.setStackFromEnd(true);
}
头尾添加的简单方法,利用多种item的布局,其中一种为FooterView。
private class MyAdapterextends RecyclerView.Adapter {
private final int PROGRESS_VIEW =0;
private final int PROMOTE_VIEW =1;
private Listpromote List;
private Context mContext;
//展开宽度
int mWidth;
private RotateAnimation animation;
public void setLoadSuccess(boolean loadSuccess) {
this.loadSuccess = loadSuccess;
}
public MyAdapter(List promoteList, Context mContext, int mWidth) {
this.promoteList = promoteList;
this.mContext = mContext;
this.mWidth = mWidth;
}
@Override
public int getItemViewType(int position) {
return promoteList.get(position) ==null ?PROGRESS_VIEW :PROMOTE_VIEW;
}
@Override
public RecyclerView.ViewHolderonCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType ==PROGRESS_VIEW) {
return new ProgressViewHolder(LayoutInflater.from(mContext).inflate(R.layout.footview, parent, false));
}else {
return new PromoteHolder(LayoutInflater.from(mContext).inflate(R.layout.promote_item_layout, parent, false));
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof PromoteHolder) {
final PromoteHolder promoteHolder = (PromoteHolder) holder;
//子布局点击事件
promoteHolder.itemView.setOnClickListener(new OnSingleClickListener() {
@Override
public void doOnClick(View v) {
}
});
}else if (holder instanceof ProgressViewHolder) {}
}
@Override
public int getItemCount() {
return promoteList.size();
}
//普通布局
class PromoteHolderextends RecyclerView.ViewHolder {
public PromoteHolder(View itemView) {
super(itemView);
}
}
//上拉加载更多底部布局
class ProgressViewHolderextends RecyclerView.ViewHolder {
public ProgressViewHolder(View itemView) {
super(itemView);
}
}