vlayout README

The project's README from github.com/alibaba/vlayout. As one markdown file: README.md.

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

vlayout

中文文档

Projects of Tangram

Android

iOS

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

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:

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

Or in maven:
pom.xml

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

Initialize LayoutManager

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.

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

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.

public class MyAdapter extends VirtualLayoutAdapter {
   ......
}

MyAdapter myAdapter = new MyAdapter(layoutManager);

//create layoutHelper list
List<LayoutHelper> helpers = new LinkedList<>();
GridLayoutHelper gridLayoutHelper = new GridLayoutHelper(4);
gridLayoutHelper.setItemCount(25);
helpers.add(gridLayoutHelper);

GridLayoutHelper gridLayoutHelper2 = new GridLayoutHelper(2);
gridLayoutHelper2.setItemCount(25);
helpers.add(gridLayoutHelper2);

//set layoutHelper list to adapter
myAdapter.setLayoutHelpers(helpers);

//set adapter to recyclerView
recycler.setAdapter(myAdapter);

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.

vlayout (alibaba/vlayout)

Searching Database…

10.7K ·GitHub
archived
这是什么?Vlayout 是 Android 的 RecyclerView 一个功能强大的 LayoutManager 扩展:它提供了一整套布局方案,让一个 RecyclerView 可以在同一个可滚动页面里混排网格、列表等多种布局。
所以它是一个加到我的 Android 项目里的库,而不是一个独立的应用?对——它是一个 Android 库:你在 RecyclerView 上设置一个自定义的 LayoutManager,它就会管理一系列 layoutHelper,每个 layoutHelper 负责实现某一段 item 位置的布局逻辑。
怎么把它加到我的项目里?从发布说明里选一个最新版本,把它添加为 Gradle 或 Maven 依赖(它发布在 jcenter 和 MavenCentral 上),然后在你的 RecyclerView 上设置 VirtualLayoutManager。
它能和我已有的 RecyclerView 代码兼容吗?可以——它直接复用你现有的 RecyclerView 和适配器。有两点需要调整:把每种 item 类型的回收视图池容量调大一些,并用 DelegateAdapter 作为根适配器来组合你的各个子适配器。
这个项目还在维护吗?不维护了。README 开头就声明项目已不再维护,仓库也已归档,所以别指望有修复或更新。另外 FAQ 目前只有中文版。
我能在商业应用里使用它吗?可以——vlayout 采用 MIT 许可证发布,这是最宽松的开源许可证之一。
开箱即用提供了哪些布局?默认内置了十种 helper:LinearLayoutHelper、GridLayoutHelper、ColumnLayoutHelper、SingleLayoutHelper、可做出瀑布流效果的 OnePlusNLayoutHelper 和 StaggeredGridLayoutHelper,以及四种固定样式(fix)的 helper,用来实现置顶或悬浮的视图。
这些 fix 样式的 helper 是干什么用的?它们把视图固定在屏幕上的某个位置,而不是随页面滚动:FixLayoutHelper 立即固定,ScrollFixLayoutHelper 在滚动时才显示,StickyLayoutHelper 在开头或结尾吸附停留,FloatLayoutHelper 则悬浮在页面上方并且可以拖动。
我能接入自己的布局逻辑吗?可以——项目明确支持自己实现 LayoutHelper 并提供给框架使用,自定义的布局逻辑可以和内置布局并存。
README 里反复提到的 Tangram 是什么?Tangram 是 vlayout 所属的页面搭建项目家族;在 Android 端它和 Tangram-Android、Virtualview-Android、UltraViewPager 并列,在 iOS 端则有 Tangram-iOS 和 LazyScrollView 等对应项目。
Creator
alibaba
Size
1.7 MB
Stars
10.7K
Age
9y
Commits · 90 Days