flexbox-layout
flexbox-layout copied to clipboard
Question: How to get the row/line for a view at certain position
- [x] I have searched existing issues and confirmed this is not a duplicate
How to get the row/line for a desired view
Is there a way to get a selected view's row/line number?, I want to know what line a view at certain position belongs to.
It's a very good question. I was struggling with it when tried to create a proper ItemDecoration. Maybe someone knows convenient way of getting the line number, line length and the position in line?
I found package-private method that is used by FlexboxItemDecoration to find out the line number.
int getPositionOnFlexLineIndex(int position)
But it is package-private and can't be used from the outside.
I found a (dirty) solution for this problem without modifying the classes of this repo manually: In your custom project, create a package with the same package name of FlexboxItemDecoratiom. Then create a new class in this package, for example "PackageProtectionCaller.java". In this class you can define static public methods and can access the package protected methods and variables.
Not a smooth solution, but sometimes the only way to handle data.