Good afternoon.
I have a RecyclerView
inside a ConstraintLayout
. The RecyclerView
receives a number of items that can vary.
How can I find out, for comparison, when the RecycerView
exceeds the screen width to put an expand button or not?
With a GridLayout
I have figured it out using .spanCount
. Another option that I have used is val column: Int = (view.layoutParams as GridLayoutManager.LayoutParams).spanIndex
, but this does not work for me in the case of the RecyclerView
within the Constraint
.
Can someone help me please? Thanks in advance
2
Answers
Thanks for the reply. I tried that but it didn't work for me. At the moment, what is working for me is:
The consumeViewTreeObserver function is a Global Observer created elsewhere so that resources are not used until they are loaded.
Still, I would be interested to know if there is a way to count for the Linear Layout if you use more than one line
Please try this:
Here, if you give negative parameter to canScrollHorizontally() it means check if it scrolls left side, positive parameter means right side