少废话,先看效果图!
分析
根据效果图我们不难看出:我们需要实现列表的折叠与展开的效果,也就是说RecylerView需要有两个状态:一个是展开状态,其实展开状态就是常规的LinearLayoutManager;另外一个是折叠的状态,这个就需要我们自定义LayoutManger实现了。
实现
public class StackLayoutManager extends RecyclerView.LayoutManager {
private static final String TAG = "StackLayoutManager";
private static final int MAX_SHOW_COUNT = 3;
private static final int CARD_VERTICAL_GAP = 20;
private Context mContext;
private Rect mViewInfo;
public StackLayoutManager(Context context) {
mContext = context;
}
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTE