Explain:

It’s extremely difficult to expand some of the mysteries of recyclerView (e.g., alipay’s bankcard page), so creating a recyclerView isn’t a fancy fancy operation.

Design:

  • Item level 3 cache can be removed or simplified as much as possible.
  • LayoutManager can be removed (The function is written in the ontology, so you can change it anyway).
  • There must be an Adapter
  • Sliding and inertial sliding are also needed

How to achieve:

It’s impossible to do it yourself, recyclerView is too complicated to be honest. Look at someone else’s code and check out the recyclerView part of it:

Github.com/loopeer/Car…

Sliding implementation

  • Custom CardStackView inherits viewGroup

    public class CardStackView extends ViewGroup { public CardStackView(Context context) { this(context, null); } public CardStackView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public CardStackView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context, attrs, defStyleAttr, 0); // Initialize a heap}}Copy the code
  • OnMeasure a bunch of height correlation tests (get the height of the display area, itemView’s actual total occupied height)

  • OnLayout to a bunch of position layouts (calculates and sets the relative position of itemView in the ontology)

  • OnInterceptTouchEvent Intercepts sliding operations

  • Handle sliding operations in onTouchEvent (after calculating sliding distance, change the real-time layout of itemView)

Data display (Adapter) implementation

  • The Adapter provides a ViewHolder to the RecylerView to create and refresh the subItemView.
  • The Adapter calls notifyDataSetChanged() to notify ReyclerView to refresh the ViewHolder.

How do ReyclerView and Adapter refresh interactively?

All that is missing is an observer :(ViewDataObserver) RecyclerViewDataObserver

Here is an example diagram of a simple implementation:



Github.com/drchengit/S…