Comments (11)
With the new API, you shouldn't need it since with originX
and originY
inside Divider
you could obtain every desired result.
Which type of logic do you have to implement?
from recycler-view-divider.
How can I achieve this complex effect
* 0;0 --------------> 1;0
* | |
* | 1 |
* ∨ ∨
* 0;1 ----> 1;1 ----> 2;1
* | | |
* | 2 | 3 |
* ∨ ∨ ∨
* 0;2 ----> 1;2 ----> 2;2
* | | |
* | 4 | 5 |
* ∨ ∨ ∨
* 0;3 ----> 1;3 ----> 2;3
- 1 is A Type
- 2, 3, 4, 5 is B Type
- Item position not fixed
from recycler-view-divider.
You can obtain the absolute index using originX
and originY
since you have the cell's span size and the grid's span count, but this would be a probably useless task.
What do you need to do in that layout? Do you want to make the vertical dividers red? Do you want to make the last divider blue? I mean, if you tell me the logic you want to implement, I'm pretty sure you can implement it without using absoluteCellIndex
.
from recycler-view-divider.
What should I do about this situation? Without item index, it's hard to know which part it is
Because:
- The size of divider is determined by the upper and lower parts
- Item position is dynamic
- Divider only as space
from recycler-view-divider.
@kjsolo You can achieve that effect with the following lines, obviously with some adaptations, like converting the size in dp
.
dividerBuilder()
.asSpace()
.sizeProvider(object : SizeProvider {
override fun getDividerSize(grid: Grid, divider: Divider, dividerDrawable: Drawable): Int = when {
divider.orientation.isHorizontal && divider.originX == 0 -> 16
divider.orientation.isHorizontal && (divider.originX == 1 || divider.originX == 3) -> 12
else -> 8
}
})
.visibilityProvider(object : VisibilityProvider {
override fun isDividerVisible(grid: Grid, divider: Divider): Boolean =
divider.orientation.isHorizontal || divider.originY != 0
})
.build()
from recycler-view-divider.
@kjsolo You can achieve that effect with the following lines, obviously with some adaptations, like converting the size in
dp
.dividerBuilder() .asSpace() .sizeProvider(object : SizeProvider { override fun getDividerSize(grid: Grid, divider: Divider, dividerDrawable: Drawable): Int = when { divider.orientation.isHorizontal && divider.originX == 0 -> 16 divider.orientation.isHorizontal && (divider.originX == 1 || divider.originX == 3) -> 12 else -> 8 } }) .visibilityProvider(object : VisibilityProvider { override fun isDividerVisible(grid: Grid, divider: Divider): Boolean = divider.orientation.isHorizontal || divider.originY != 0 }) .build()
I can not use this code: divider.originX == 0
, because item position is dynamic, they can swap index. It may be another situation:
from recycler-view-divider.
The absoluteCellIndex
can't be exposed because with the new API, the dividers changed the way they behave and the same divider can be owned by two different items, unlike the previous version. We can try to find a specific solution for your problem though, without changing the library. Can you post here the part of your code in which you decide if the view type is A, B or C?
from recycler-view-divider.
Without absoluteCellIndex, I can only get this value in this way:
// This code waste a lot of time if there's a lot of data
fun Grid.itemIndex(lineIndex: Int, cellIndex: Int): Int {
return lines.take(lineIndex).sumBy { it.cellsCount } + cellIndex
}
And here the code that's why I need it:
fun getSideDividerSize(itemIndex: Int): Int {
val item = dataList[itemIndex]
when (item) {
is A -> 0.dp
else -> 8.dp
}
}
fun getHorizontalDividerSize(beforeItemIndex: Int, afterItemIndex: Int): Int {
val beforeItem = dataList[beforeItemIndex]
val afterItem = dataList[afterItemIndex]
return when (afterItem) {
is A -> 12.dp
is B -> 8.dp
is C -> {
when (beforeItem) {
is A, B -> 16.dp
else -> 36.dp
}
}
else -> 0
}
}
fun getVerticalDividerSize(beforeItemIndex: Int, afterItemIndex: Int): Int {
val afterItem = dataList[afterItemIndex]
when (afterItem) {
is B -> 8.dp
}
}
from recycler-view-divider.
How can you access the line index and the cell index?
Because, if you are using originX
and originY
, they can match the line/cell before or the line/cell after depending on when they are invoked.
(BTW, you can cache the computation of Grid.itemIndex()
to make it way faster)
from recycler-view-divider.
line/cell has a relationship with origin
val lineIndex: Int
val cellIndex: Int
if (orientation.isVertical) {
lineIndex = divider.originY
cellIndex = divider.originX
} else {
lineIndex = divider.originX
cellIndex = divider.originY
}
from recycler-view-divider.
Those lines are referred to accumulatedSpan
which is internal
and can't be exposed because it relies on a specific usage which subtract 1 if the divider is before the item (look at DividerOffsetProviderImpl
). This is the problem I was talking about before. You can't access the side on which the divider is going to show so you can't know if the divider is before or after the item.
from recycler-view-divider.
Related Issues (20)
- Animate divider
- GridLayoutManager item height not equal HOT 4
- Run tests on Android Q HOT 1
- Update Android 11
- "GridLayoutManager.multipleSpanGrid" It takes too much time with a large data set HOT 4
- visibilityProvider is not working fine with GridLayoutMananger HOT 3
- Grag Item,the space will bigger and bigger HOT 4
- Fix sourceSets deprecation in CoveragePlugin
- Crash: The grid doesn't contain the item at position... HOT 3
- Equal Spacing HOT 2
- How to set float size decoration? HOT 2
- The size of the divider is wrong after notifyItemRemoved() HOT 2
- How to use the SizeProvider HOT 1
- 使用说明可以详细一些么 HOT 2
- Try JaCoCo report aggregation
- Upgrade Releases Hub Plugin to v4.0.0 HOT 1
- Failed to allocate a xxx0 byte allocation with xxx free bytes and 503MB until OOM, HOT 2
- Dependency Dashboard
- GridView
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from recycler-view-divider.