一个超轻量级的RecycleViewAdapter辅助类库

EasyRecycleAdapterHelper

一个简单实用的RecycleViewAdapter帮助库

简介

  • 1.RecycleView的OnItemClick,OnItemLongClick的点击事件
  • 2.RecycleView的Item动画,默认实现了一种动画效果,可自行扩展
  • 3.添加头部尾部,分割线
  • 4.列表和表格布局的上拉加载更多

Tips

  • 该库并没有实现下拉刷新,因为考虑到对下拉刷新的需求不一致,所以暂不提供,可自实现,该库只是提供一个对RecycleView的使用的封装,处理了一些常见的需求,有什么问题可以给我提issuse.

截图

添加依赖

To get a Git project into your build:Step
1. Add the JitPack repository to your build fileAdd it in your root build.gradle at    the end of repositories:  
allprojects {     
repositories {       
 ...        
maven { url "https://jitpack.io" }    
 }  }

Step 2. Add the dependency 

dependencies {          
compile 'com.github.HotBitmapGG:EasyRecycleAdapterHelper:V1.1'   } 

使用说明&Demo


* Adapter
@Override public ClickableViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {   

//绑定上下文   
bindContext(parent.getContext());    

//创建ViewHolder   
return new ItemViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.item_main, parent, false));
}

@Override public void onBindViewHolder(ClickableViewHolder holder, int position) {   

if (holder instanceof ItemViewHolder){        
 ItemViewHolder itemViewHolder = (ItemViewHolder) holder;     
 itemViewHolder.mTextView.setText(datas.get(position));     

//添加动画         
showItemAnim(itemViewHolder.mLayout, position); 
}     

super.onBindViewHolder(holder, position); }

* Activity

//初始化
RecycleViewmRecyclerView = (RecyclerView) findViewById(R.id.recycle_view);
assert mRecyclerView != null;
mRecyclerView.setHasFixedSize(true);

//设置LayoutManager
LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLinearLayoutManager);

//设置分割线
mRecyclerView.addItemDecoration(new EasyDividerItemDecoration(this ,EasyDividerItemDecoration.VERTICAL_LIST));

//创建Adapter
mRecycleAdapter = new RecycleAdapter(mRecyclerView, datas);

//使用EasyAdapter包装一层 添加头部 尾部
EasyRecycleAdapter mEasyRecycleAdapter = new EasyRecycleAdapter(mRecycleAdapter);

//添加头部
createHead();
mEasyRecycleAdapter.addHeaderView(headView);

//添加尾部 上拉加载更多
createFoot();
mEasyRecycleAdapter.addFooterView(footView);

//设置适配器
mRecyclerView.setAdapter(mEasyRecycleAdapter);

//添加Scroll监听 上拉加载更多数据
mRecyclerView.addOnScrollListener(new EasyRecycleOnScrollListener(mLinearLayoutManager){   
@Override   
public void onLoadMore(int currentPage)  
{       
  //这里是上拉更多数据的逻辑       
   page++;      
   loadMoreData();   
}
});

//设置item点击事件
mRecycleAdapter.setOnItemClickListener(new EasyBaseRecycleViewAdapter.OnItemClickListener(){   
@Override   
public void onItemClick(int position, EasyBaseRecycleViewAdapter.ClickableViewHolder holder) {   

 Toast.makeText(MainActivity.this, datas.get(position),   
 Toast.LENGTH_SHORT).show();  
}
});

//初始化尾部
private void createFoot(){   
footView = LayoutInflater.from(this).inflate(R.layout.load_more_foot_layout, mRecyclerView, false);
}

//初始化头部
private void createHead(){  
headView = LayoutInflater.from(this).inflate(R.layout.layout_recycle_head, mRecyclerView, false);
}

GitHub

https://github.com/HotBitmapGG/EasyRecycleAdapterHelper

关于我

https://github.com/HotBitmapGG

你可能感兴趣的:(一个超轻量级的RecycleViewAdapter辅助类库)