Vlayout is a basic open source UI framework for Alibaba to quickly implement complex layouts. It is used in both Taobao and Tmall apps.
Let’s take a look at the official introduction:
VirtualLayout is a LayoutManager extension for RecyclerView, mainly provides a set of layout schemes and components between the layout reuse problems.
Through the customized LayoutManager, take over the whole RecyclerView layout logic; The LayoutManager manages a set of LayoutHelper, which is responsible for where the specific layout logic is implemented; Each LayoutHelper is responsible for the layout of components within a certain area of the page; Different LayoutHelper can do different layout logic, so you can provide heterogeneous layout structure in a RecyclerView page, which can provide richer capabilities than the system LinearLayoutManager, GridLayoutManager and so on. LayoutHelper is also supported to provide more layout capabilities.
Starting from the RecyclerView
VLayout mainly expanded from RecyclerView, we started from RecyclerView, first look at a few key elements in RecyclerView:
-
RecyclerView. LayoutManager is mainly responsible for in RecyclerView ItemView layout, we often use its subclasses:
-
RecyclerView. ItemDecoration to add each Item View View, can increase directly in the Item line etc
-
RecyclerView. ItemAnimator responsible for dealing with the Item when add or remove the animation effects
-
RecyclerView.Adapter provides ViewHolder for each positon
-
RecyclerView.ViewHolder is responsible for the layout of Item itself and participates in the cache strategy of RecyclerView.
The thinking of VLayout
VLayout extension from the official website is mainly LayoutManager, specific layout logic in LayoutHelper implementation. Vlayout provides a wide variety of LayoutHelper implementations, and it is also very easy to extend and implement custom LayoutHelper.
The list you can see above has a variety of layouts that LayoutHelper has contributed to.
We know that there is only one layout in RecyclerView normally. If different layouts are needed in the list, different itemTypes can be set and multiple ViewHolder can be provided to achieve this.
VLayout takes a different approach. It inherits RecyclerView.Adapter to implement DelegateAdapter, and uses DelegateAdapter to display complex layouts. It also implements its own cache.
The principle of DelegateAdapter is to concatenate adapters that inherit from RecyclerView.Adapter to manage data and view adaptation:
So each adapter and layouthelper is responsible for one area, and each area has multiple ItemViews.
The DelegateAdapter is responsible for combining multiple adapters, shown in RecyclerView.
One of the obvious disadvantages of this is that each sub-adapter is only responsible for one contiguous area, and if there are multiple areas that need the same Adapter, you need to add adapters twice.
VLayout usage scenario
From the above analysis, I think the layout similar to Taobao in this form is very suitable for using VLayout, and VLayout provides a variety of layoutHelper, very convenient to use.
But if it is similar to weibo, wechat Feed flow based interface, the use of VLayout and no advantage, the implementation of the complexity.
Welcome to wutongke, a public account, to regularly push articles on cutting-edge technology in mobile development:
Recommended reading
Talk about Litho, Facebook’s open source Litho, and use ConstraintLayout to make beautiful animations