UltimateRecyclerView 是一个 RecyclerView(Android中ListView的高级灵活版),具有刷新、加载更多、动画等多种功能。
功能- 滑动刷新
- 多种动画
- 滑动关闭
- 视差或正常头部视图
- 拖放项目
- 到达最后一项时加载更多(无限滚动)
- 加载更多的自定义视图
- 滚动时显示或隐藏工具栏和浮动按钮
- 滚动条
- 多彩风格的刷卡刷新
- 像 instagram 这样的粘性标题
- 支持适配器中的不同布局
- 加载带有动画的适配器
- recyclerview 中的可扩展视图
1. 添加依赖
repositories {
jcenter()
}
dependencies {
...
implementation 'com.marshalchen.ultimaterecyclerview:library:0.9.0'
}
2. 布局文件
- main_activity.xml
- exp_parent.xml
- exp_child.xml
3. Bean 类
- Category.java
public class Category extends easyTemplateParent {
public Category(View itemView) {
super(itemView);
}
}
- SubCategory.java
public class SubCategory extends easyTemplateChild {
public SubCategory(View itemView) {
super(itemView);
}
}
4. 适配器
public class ExpCustomAdapter extends customizedAdapter {
public ExpCustomAdapter(Context context) {
super(context);
}
public static List getPreCodeMenu(String[] a, String[] b, String[] c) {
List e = new ArrayList();
e.add(SmartItem.parent("世界名著", "open", DataUtil.getSmallList(a)));
e.add(SmartItem.parent("推荐书籍", "open", DataUtil.getSmallList(b)));
e.add(SmartItem.parent("体育明星", "open", DataUtil.getSmallList(c)));
return e;
}
/**
* please do work on this id the custom object is true
*
* @param parentview the inflated view
* @return the actual parent holder
*/
@Override
protected Category iniCustomParentHolder(View parentview) {
return new Category(parentview);
}
/**
* please do work on this if the custom object is true
*
* @param childview the inflated view
* @return the actual child holder
*/
@Override
protected SubCategory iniCustomChildHolder(View childview) {
return new SubCategory(childview);
}
@Override
protected int getLayoutResParent() {
return R.layout.exp_parent;
}
@Override
protected int getLayoutResChild() {
return R.layout.exp_child;
}
@Override
protected List getChildrenByPath(String path, int depth, int position) {
return null;
}
@Override
public RecyclerView.ViewHolder newFooterHolder(View view) {
return new UltimateRecyclerviewViewHolder(view);
}
@Override
public RecyclerView.ViewHolder newHeaderHolder(View view) {
return new UltimateRecyclerviewViewHolder(view);
}
}
5. MainActivity.java
public class MainActivity extends AppCompatActivity {
private static String[] sampledatagroup1 = {
"《论语》", "http://google",
"《三国演义》", "http://google",
"《红与黑》", "http://google",
"《老人与海》", "http://google"
};
private static String[] sampledatagroup2 = {
"《第一行代码》", "http://google",
"《代码整洁之道》", "http://google",
"《重构》", "http://google",
"《程序员的职业素养》", "http://google",
"《如何阅读》", "http://google"
};
private static String[] sampledatagroup3 = {
"科比", "http://google",
"C罗", "http://google",
"林丹", "http://google",
"刘德华", "http://google",
"周杰伦", "http://google"
};
@BindView(R.id.recycler_view)
UltimateRecyclerView mRecyclerView;
@BindView(R.id.topbar)
QMUITopBar mTopBar;
private ExpCustomAdapter simpleRecyclerViewAdapter = null;
private LinearLayoutManager linearLayoutManager;
private ActionMode actionMode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
initView();
}
private void initView() {
mTopBar.setTitle("二级列表");
mTopBar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
mRecyclerView.setHasFixedSize(false);
simpleRecyclerViewAdapter = new ExpCustomAdapter(this);
simpleRecyclerViewAdapter.addAll(ExpCustomAdapter.getPreCodeMenu(sampledatagroup1, sampledatagroup2, sampledatagroup3), 0);
linearLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(linearLayoutManager);
mRecyclerView.setAdapter(simpleRecyclerViewAdapter);
mRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff"));
addExpandableFeatures();
}
private void addExpandableFeatures() {
mRecyclerView.getItemAnimator().setAddDuration(100);
mRecyclerView.getItemAnimator().setRemoveDuration(100);
mRecyclerView.getItemAnimator().setMoveDuration(200);
mRecyclerView.getItemAnimator().setChangeDuration(100);
}
}