0

I want to change layoutmanager stackFromEnd and reverseLayout change when view is inflated. I have nested recylerview. So when recylerview inflated, i need to check that recylerview has more item than single screen i.e. I have more than items to scroll. I will show in image.

enter image description here

Also other condition when item is half cut from bottom edge.

enter image description here.

On that basis I want to change layout on that. Is it possible to that and how? I tried to some stack overflow Example but it not's work. So anyone know how to achieve that thing?.

So I wonder if there is any listener that is called when the RecyclerView has finished laying down its items for the first time, making it possible to set the layout manager.

Kotlin Learner
  • 3,995
  • 6
  • 47
  • 127

1 Answers1

1

Im assuming you have a parent view for your recycler views, e.g. NestedScrollView. Then you will need to get the height of your NestedScrollView after it being created in your screen

var nestedScrollViewHeight = 0
yourNestedScrollView.viewTreeObserver.addOnGlobalLayoutListener(
            object : ViewTreeObserver.OnGlobalLayoutListener {
                override fun onGlobalLayout() {
                    yourNestedScrollView.viewTreeObserver.removeOnGlobalLayoutListener(this)
                    nestedScrollViewHeight = yourNestedScrollView.height
                }
            }
        )

And then you can check whether this NestedScrollView height surpass your screen height, you can get your screen height using windowManager in Activity

val screenHeight = windowManager.currentWindowMetrics.bounds.height()

So, after obtaining both screenHeight and nestedScrollViewHeight you can then substract to check whether nestedScrollViewHeight is larger than screenHeight

Putra Nugraha
  • 574
  • 1
  • 4
  • 12
  • thanks for example. Where need to put this code inside my activity or in my first adapter where I'm setting my second adapter?. Also if in my activity how can i acces my second adapter RV? – Kotlin Learner Oct 27 '21 at 07:22
  • I think need you to update your question by put your code, that should make clear where to put this code – Putra Nugraha Oct 28 '21 at 01:38