Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
V

vlayout

> 编程语言
Open source

Project vlayout is a powerfull LayoutManager extension for RecyclerView, it provides a group of layouts for RecyclerView. Make it able to handle a complicate si

10.7K stars0 likes0 views
WebsiteGitHub

About

Project vlayout is a powerfull LayoutManager extension for RecyclerView, it provides a group of layouts for RecyclerView. Make it able to handle a complicate si

Attention. This project is not maintained any more !!!

vlayout

中文文档

Projects of Tangram

Android

  • Tangram-Android
  • Virtualview-Android
  • vlayout
  • UltraViewPager

iOS

  • Tangram-iOS
  • Virtualview-iOS
  • LazyScrollView

Project vlayout is a powerful LayoutManager extension for RecyclerView, it provides a group of layouts for RecyclerView. Make it able to handle a complicate situation when grid, list and other layouts in the same recyclerview.

Design

By providing a custom LayoutManager to RecyclerView, VirtualLayout is able to layout child views with different style at single view elegantly. The custom LayoutManager manages a serial of layoutHelpers where each one implements the specific layout logic for a certain position range items. By the way, implementing your custom layoutHelper and provding it to the framework is also supported.

Main Feature

  • Provide default common layout implementation, decouple the View and Layout. Default layout implementations are:
    • LinearLayoutHelper: provide linear layout as LinearLayoutManager.
    • GridLayoutHelper: provide grid layout as GridLayoutManager, but with more feature.
    • FixLayoutHelper: fix the view at certain position of screen, the view does not scroll with whole page.
    • ScrollFixLayoutHelper: fix the view at certain position of screen, but the view does not show until it scrolls to it position.
    • FloatLayoutHelper: float the view on top of page, user can drag and drop it.
    • ColumnLayoutHelper: perform like GridLayoutHelper but layouts all child views in one line.
    • SingleLayoutHelper: contain only one child view.
    • OnePlusNLayoutHelper: a custom layout with one child view layouted at left and the others at right, you may not need this.
    • StickyLayoutHelper: scroll the view when its position is inside the screen, but fix the view at start or end when its position is outside the screen.
    • StaggeredGridLayoutHelper: provide waterfall like layout as StaggeredGridLayoutManager.
  • LayoutHelpers provided by default can be generally divided into two categories. One is non-fix LayoutHelper such as LinearLayoutHelper, GridLayoutHelper, etc which means the children of these LayoutHelper will be layouted in the flow of parent container and will be scrolled with the container scrolling. While the other is fix LayoutHelper which means the child of these is always fix in parent container.

Usage

Import Library

Please find the latest version in release notes. The newest version has been upload to jcenter and MavenCentral, make sure you have added at least one of these repositories. As follow:

For gradle:

gradle
compile ('com.alibaba.android:vlayout:1.2.8@aar') {
	transitive = true
}

Or in maven:
pom.xml

xml
<dependency>
  <groupId>com.alibaba.android</groupId>
  <artifactId>vlayout</artifactId>
  <version>1.2.8</version>
  <type>aar</type>
</dependency>

Initialize LayoutManager

java
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);

recyclerView.setLayoutManager(layoutManager);

Initialize recycled pool's size

Provide a reasonable recycled pool's size to your recyclerView, since the default value may not meet your situation and cause re-create views when scrolling.

java
RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
recyclerView.setRecycledViewPool(viewPool);
viewPool.setMaxRecycledViews(0, 10);

Attention: the demo code above only modify the recycle pool size of item with type = 0, it you has more than one type in your adapter, you should update recycle pool size for each type.

Set Adapters

  • You can use DelegateAdapter for as a root adapter to make combination of your own adapters. Just make it extend DelegateAdapter.Adapter and overrides onCreateLayoutHelper method.
java
DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, hasConsistItemType);
recycler.setAdapter(delegateAdapter);

// Then you can set sub- adapters

delegateAdapter.setAdapters(adapters);

// or
CustomAdapter adapter = new CustomAdapter(data, new GridLayoutHelper());
delegateAdapter.addAdapter(adapter);

// call notify change when data changes
adapter.notifyDataSetChanged();

Attention: When hasConsistItemType = true, items with same type value in different sub-adapters share the same type, their view would be reused during scroll. When hasConsistItemType = false, items with same type value in different sub-adapters do not share the same type internally.

  • The other way to set adapter is extending VirtualLayoutAdapter and implementing it to make deep combination to your business code.
…

In this way, one thing you should note is that you should call setLayoutHelpers when the data of Adapter changes.

Config proguard

Add following configs in your proguard file if your app is released with proguard.

-keepattributes InnerClasses
-keep class com.alibaba.android.vlayout.ExposeLinearLayoutManagerEx { *; }
-keep class android.support.v7.widget.RecyclerView$LayoutParams { *; }
-keep class android.support.v7.widget.RecyclerView$ViewHolder { *; }
-keep class android.support.v7.widget.ChildHelper { *; }
-keep class android.support.v7.widget.ChildHelper$Bucket { *; }
-keep class android.support.v7.widget.RecyclerView$LayoutManager { *; }

Demo

Demo Project

FAQ

Read FAQ(In Chinese language only now) before submitting issue: FAQ。

Layout Attributes

Each layoutHelper has a few attributes to control its layout style. See this to read more.

Contributing

Before you open an issue or create a pull request, please read Contributing Guide first.

LICENSE

Vlayout is available under the MIT license.

Issues· 194 open

View all issuesOpen on GitHub
  • #382

    请问vlayout可以支持FragmentPagerAdapter么?

    Updated Jul 3, 2021
  • #124

    外层加scrollview 数据不显示

    Updated Jul 3, 2021
  • #379

    使用VLayout后,当RecyclerView滚动到底部后,调用canScrollVertically返回的值不正确

    Updated Jul 1, 2021
  • #511

    edittext软键盘弹出时,edittext无法弹上去

    Updated Jun 28, 2021
  • #467

    NullPointerException

    Updated Jun 4, 2021
  • #476

    AndroidX混淆后,滑动异常,在线等

    Updated May 31, 2021
  • #526

    使用StaggeredGridLayoutHelper 进行瀑布流时,发现切换数据会导致新数据的item位置错乱问题

    Updated May 22, 2021
  • #512

    是不是不支持recyclerview的Item里嵌套一个ChildRec也是使用VLayout ,嵌套的ChildRec(这个ChildRec的数据是不固定),外层item的高度设置Wrap_parent 不显示了。要想使用VLayout 是不是xml根结点必须设置match_parent 或者固定高度!

    Updated May 13, 2021
  • #493

    输入法冲突问题

    Updated Apr 2, 2021
  • #495

    使用StaggeredGridLayoutHelper加载瀑布流,上拉加载以后重新向上滑动,item会闪烁,我想用setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);这个方法怎么调用,求大神给个思路。

    Updated Mar 31, 2021

> Tags

Javaandroidlayoutlayout-managerlayoutmanager

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言