-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Built application files | ||
*.apk | ||
*.ap_ | ||
|
||
# Files for the Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
.classpath | ||
.project | ||
.settings/ | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
#Log Files | ||
*.log | ||
|
||
# OS X | ||
.DS_Store | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.war | ||
*.ear | ||
*.iml | ||
|
||
# IDEA Files | ||
.idea/ | ||
out/ | ||
|
||
# MAVEN COMPILE Files | ||
target/ | ||
lint.xml |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 Alibaba Group | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# vlayout | ||
|
||
[English Document](README.md) | ||
|
||
VirtualLayout是一个针对RecyclerView的LayoutManager扩展, 主要提供一整套布局方案和布局间的组件复用的问题。 | ||
|
||
## 设计思路 | ||
|
||
通过定制化的LayoutManager,接管整个RecyclerView的布局逻辑;LayoutManager管理了一系列LayoutHelper,LayoutHelper负责具体布局逻辑实现的地方;每一个LayoutHelper负责页面某一个范围内的组件布局;不同的LayoutHelper可以做不同的布局逻辑,因此可以在一个RecyclerView页面里提供异构的布局结构,这就能比系统自带的LinearLayoutManager、GridLayoutManager等提供更加丰富的能力。同时支持扩展LayoutHelper来提供更多的布局能力。 | ||
|
||
## 主要功能 | ||
|
||
* 默认通用布局实现,解耦所有的View和布局之间的关系: Linear, Grid, 吸顶, 浮动, 固定位置等。 | ||
* LinearLayoutHelper: 线性布局 | ||
* GridLayoutHelper: Grid布局, 支持横向的colspan | ||
* FixLayoutHelper: 固定布局,始终在屏幕固定位置显示 | ||
* ScrollFixLayoutHelper: 固定布局,但之后当页面滑动到该图片区域才显示, 可以用来做返回顶部或其他书签等 | ||
* FloatLayoutHelper: 浮动布局,可以固定显示在屏幕上,但用户可以拖拽其位置 | ||
* ColumnLayoutHelper: 栏格布局,都布局在一排,可以配置不同列之间的宽度比值 | ||
* SingleLayoutHelper: 通栏布局,只会显示一个组件View | ||
* OnePlusNLayoutHelper: 一拖N布局,可以配置1-5个子元素 | ||
* StickyLayoutHelper: stikcy布局, 可以配置吸顶或者吸底 | ||
* StaggeredGridLayoutHelper: 瀑布流布局,可配置间隔高度/宽度 | ||
* 上述默认实现里可以大致分为两类:一是非fix类型布局,像线性、Grid、栏格等,它们的特点是布局在整个页面流里,随页面滚动而滚动;另一类就是fix类型的布局,它们的子节点往往不随页面滚动而滚动。 | ||
* 所有除布局外的组件复用,VirtualLayout将用来管理大的模块布局组合,扩展了RecyclerView,使得同一RecyclerView内的组件可以复用,减少View的创建和销毁过程。 | ||
|
||
|
||
## 使用 | ||
|
||
初始化```LayoutManager``` | ||
|
||
```java | ||
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); | ||
final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this); | ||
|
||
recyclerView.setLayoutManager(layoutManager); | ||
``` | ||
|
||
|
||
加载数据时有两种方式: | ||
|
||
* 一种是使用 ```DelegateAdapter```, 可以想平常一样写继承自```DelegateAdapter.Adapter```的Adapter, 只比之前的Adapter需要多重载```onCreateLayoutHelper```方法。 | ||
其他的和默认Adapter一样。 | ||
|
||
```java | ||
DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, hasStableItemType); | ||
recycler.setAdapter(delegateAdapter); | ||
|
||
// 之后可以通过 setAdapters 或 addAdapter方法添加Adapter | ||
|
||
delegateAdapter.setAdapters(adapters); | ||
|
||
// or | ||
CustomAdapter adapter = new CustomAdapter(data, new GridLayoutHelper()); | ||
delegateAdapter.addAdapter(adapter); | ||
|
||
``` | ||
|
||
* 另一种是当业务有自定义的复杂需求的时候, 可以继承自```VirtualLayoutAdapter```, 实现自己的Adapter | ||
|
||
```java | ||
public class MyAdapter extends VirtualLayoutAdapter { | ||
.... | ||
} | ||
|
||
``` | ||
|
||
在这种情况下,需要使用者注意在当```LayoutHelpers```的结构或者数据数量等会影响到布局的元素变化时,需要主动调用```setLayoutHepers```去更新布局模式。 | ||
|
||
|
||
推荐使用第一种方式,简单方便,开发者也很熟悉。 | ||
|
||
# Demo | ||
|
||
[Demo工程]() | ||
|
||
# 布局属性 | ||
|
||
每一种layoutHelper都有自己的布局属性来控制布局样式,详情请参考[文档](docs/ATTRIBUTES-ch.md)。 | ||
|
||
# 开源许可证 | ||
|
||
vlayout遵循MIT开源许可证协议。 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# vlayout | ||
|
||
[中文文档](README-ch.md) | ||
|
||
Project `vlayout` is a powerfull 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 implements, decouple the View and Layout. Default layout implements are: | ||
* LinearLayoutHelper: provide linear layout as LinearLayoutManager. | ||
* GridLayoutHelper: privide 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 | ||
|
||
### Initialize LayoutManager | ||
|
||
```java | ||
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); | ||
final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this); | ||
|
||
recyclerView.setLayoutManager(layoutManager); | ||
``` | ||
|
||
### 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, hasStableItemType); | ||
recycler.setAdapter(delegateAdapter); | ||
|
||
// Then you can set sub- adapters | ||
|
||
delegateAdapter.setAdapters(adapters); | ||
|
||
// or | ||
CustomAdapter adapter = new CustomAdapter(data, new GridLayoutHelper()); | ||
delegateAdapter.addAdapter(adapter); | ||
|
||
``` | ||
|
||
* The other way to set adapter is extending ```VirtualLayoutAdapter``` and implementing it to make deep combination to your business code. | ||
|
||
```java | ||
public class MyAdapter extends VirtualLayoutAdapter { | ||
.... | ||
} | ||
|
||
``` | ||
|
||
In this way, one thing you should note is that you should call ```setLayoutHelpers``` when the data of Adapter changes. | ||
|
||
# Demo | ||
|
||
[Demo Project]() | ||
|
||
# Layout Attributes | ||
|
||
Each layoutHelper has a few attributes to control its layout style. See [this](docs/ATTRIBUTES.md) to read more. | ||
|
||
# LICENSE | ||
|
||
Vlayout is available under the MIT license. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2016 Alibaba Group | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
repositories { | ||
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } | ||
mavenCentral() | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.2.2' | ||
classpath 'com.github.xfumihiro.view-inspector:view-inspector-plugin:0.1.1' | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } | ||
jcenter() | ||
mavenLocal() | ||
} | ||
} |