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
What is this?Vlayout is a powerful LayoutManager extension for Android's RecyclerView: it provides a group of layouts so a single RecyclerView can mix grid, list and other layouts in one scrollable page.
So it's a library I add to my Android project, not a standalone app?Right — it is an Android library: you set a custom LayoutManager on your RecyclerView, and it manages a series of layoutHelpers, each implementing the layout logic for a certain range of item positions.
How do I add it to my project?Pick the latest version from the release notes and add it as a Gradle or Maven dependency (it is published to jcenter and MavenCentral), then set the VirtualLayoutManager on your RecyclerView.
Does it play nicely with the RecyclerView code I already have?Yes — it rides on your existing RecyclerView and adapters. Two tweaks to know: raise the recycled view pool size per item type, and use DelegateAdapter as a root adapter to combine your sub-adapters.
Is the project still maintained?No. The README opens with a notice that the project is not maintained any more, and the repository is archived, so expect no fixes or updates. The FAQ is also available in Chinese only.
Can I use it in a commercial app?Yes — vlayout is available under the MIT license, one of the most permissive open-source licenses.
Which layouts come out of the box?Ten helpers ship by default: LinearLayoutHelper, GridLayoutHelper, ColumnLayoutHelper, SingleLayoutHelper, OnePlusNLayoutHelper and StaggeredGridLayoutHelper for a waterfall look, plus four fix-style helpers for pinned or floating views.
What are the fix-style helpers for?They pin a view to a screen position instead of scrolling with the page: FixLayoutHelper pins it right away, ScrollFixLayoutHelper reveals it on scroll, StickyLayoutHelper sticks at start or end, and FloatLayoutHelper floats on top and is draggable.
Can I plug in my own layout logic?Yes — implementing your own LayoutHelper and providing it to the framework is explicitly supported, so custom layout logic can sit alongside the built-ins.
What is Tangram, which the README keeps mentioning?Tangram is the family of page-building projects vlayout belongs to; on Android it sits alongside Tangram-Android, Virtualview-Android and UltraViewPager, with iOS counterparts such as Tangram-iOS and LazyScrollView.
Creator
alibaba
Size
1.7 MB
Stars
10.7K
Age
9y
Commits · 90 Days