最后
看完上述知识点如果你深感Java基础不够扎实,或者刷题刷的不够、知识不全面
小编专门为你量身定制了一套<Java一线大厂高岗面试题解析合集:JAVA基础-中级-高级面试+SSM框架+分布式+性能调优+微服务+并发编程+网络+设计模式+数据结构与算法>
针对知识面不够,也莫慌!还有一整套的<Java核心进阶手册>,可以瞬间查漏补缺
全都是一丢一丢的收集整理纯手打出来的
更有纯手绘的各大知识体系大纲,可供梳理:Java筑基、MySQL、Redis、并发编程、Spring、分布式高性能架构知识、微服务架构知识、开源框架知识点等等的xmind手绘图~
BaseRecyclerViewAdapterHelper源码解读(五) header和footer完善
BaseRecyclerViewAdapterHelper源码解读(六) 分组布局
使用
–
优点:
- 简单配置、无需重写额外方法。
- 可以设置默认布局类型
- 可以设置item布局的跨度
- 轻松添加新布局类型
使用方法:
1.写一个实体类,必须实现MultiItemEntity接口,并且尽量有itemType(用于标识该item是什么type)和spanSize(该item的跨度).
public class MultipleItem implements MultiItemEntity {
public static final int TEXT = 1;
public static final int IMG = 2;
public static final int IMG_TEXT = 3;
public static final int TEXT_SPAN_SIZE = 3;
public static final int IMG_SPAN_SIZE = 1;
public static final int IMG_TEXT_SPAN_SIZE = 4;
public static final int IMG_TEXT_SPAN_SIZE_MIN = 2;
private int itemType;
/**
- 跨度
*/
private int spanSize;
public MultipleItem(int itemType, int spanSize, String content) {
this.itemType = itemType;
this.spanSize = spanSize;
this.content = content;
}
public MultipleItem(int itemType, int spanSize) {
this.itemType = itemType;
this.spanSize = spanSize;
}
public int getSpanSize() {
return spanSize;
}
public void setSpanSize(int spanSize) {
this.spanSize = spanSize;
}
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Override
public int getItemType() {
return itemType;
}
}
2.定义一个adapter,继承自BaseMultiItemQuickAdapter(必须),然后在构造方法中添加你这个RecyclerView的相关的item全部添加上。
然后在convert()方法里面绑定数据即可,绑定数据的时候记得如果添加了header,那么需要索引需要-1。
public class MultipleItemQuickAdapter extends BaseMultiItemQuickAdapter<MultipleItem, BaseViewHolder> {
public MultipleItemQuickAdapter(Context context, List data) {
super(data);
addItemType(MultipleItem.TEXT, R.layout.item_text_view);
addItemType(MultipleItem.IMG, R.layout.item_image_view);
addItemType(MultipleItem.IMG_TEXT, R.layout.item_img_text_view);
}
@Override
protected void convert(BaseViewHolder helper, MultipleItem item) {
switch (helper.getItemViewType()) {
case MultipleItem.TEXT:
helper.setText(R.id.tv, item.getContent());
break;
case MultipleItem.IMG_TEXT:
switch (helper.getLayoutPosition() %
- {
case 0:
helper.setImageResource(R.id.iv, R.mipmap.animation_img1);
break;
case 1:
helper.setImageResource(R.id.iv, R.mipmap.animation_img2);
break;
}
break;
}
}
}
定做一个BaseMultiItemQuickAdapter
在定制adapter之前,我们先来了解一下SparseIntArray
SparseIntArrays map integers to integers. Unlike a normal array of integers, there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Integers to Integers, both because it avoids auto-boxing keys and values and its data structure doesn’t rely on an extra entry object for each mapping.
Note that this container keeps its mappings in an array data structure, using a binary search to find keys. The implementation is not intended to be appropriate for data structures that may contain large numbers of items. It is generally slower than a traditional HashMap, since lookups require a binary search and adds and removes require inserting and deleting entries in the array. For containers holding up to hundreds of items, the performance difference is not significant, less than 50%.
It is possible to iterate over the items in this container using keyAt(int) and valueAt(int). Iterating over the keys using keyAt(int) with ascending values of the index will return the keys in ascending order, or the values corresponding to the keys in ascending order in the case of valueAt(int).
上面是官方介绍,下面是翻译:
SparseIntArrays将整数映射到整数。与正常的整数数组不同,索引中可能存在差距。它旨在比使用HashMap将整数映射到整数更有效率,因为它避免了自动打包(装箱)键和值,并且其数据结构不依赖于每个映射的额外的条目对象。
请注意,此容器将其映射保存在数组数据结构中,使用二进制搜索查找密钥。该实现并不适用于可能包含大量项目的数据结构。它通常比传统的HashMap更慢,因为查找需要二进制搜索,并添加和删除需要插入和删除数组中的条目。对于容纳数百种物品的容器,性能差异不显着,小于50%。
可以使用keyAt(int)和valueAt(int)迭代此容器中的项目。使用keyAt(int)使用keyAt(int)迭代索引的值将以升序返回键值,或者在valueAt(int)的情况下按升序对应的键值。
由于我们是需要实现多布局,于是我们需要引入不同的type和对应的不同的布局,这里开源库中使用的是SparseIntArray来存储这些数据.key是type,value是layoutResId.
下面我们来看看adapter源码
总结
虽然面试套路众多,但对于技术面试来说,主要还是考察一个人的技术能力和沟通能力。不同类型的面试官根据自身的理解问的问题也不尽相同,没有规律可循。
上面提到的关于这些JAVA基础、三大框架、项目经验、并发编程、JVM及调优、网络、设计模式、spring+mybatis源码解读、Mysql调优、分布式监控、消息队列、分布式存储等等面试题笔记及资料
有些面试官喜欢问自己擅长的问题,比如在实际编程中遇到的或者他自己一直在琢磨的这方面的问题,还有些面试官,尤其是大厂的比如 BAT 的面试官喜欢问面试者认为自己擅长的,然后通过提问的方式深挖细节,刨根到底。
比如在实际编程中遇到的或者他自己一直在琢磨的这方面的问题,还有些面试官,尤其是大厂的比如 BAT 的面试官喜欢问面试者认为自己擅长的,然后通过提问的方式深挖细节,刨根到底。