[英]Change layout Manager programatically in recylerview android
I want to change layoutmanager stackFromEnd and reverseLayout change when view is inflated.我想在视图膨胀时更改layoutmanager stackFromEnd和reverseLayout更改。 I have nested recylerview.
我嵌套了 recylerview。 So when recylerview inflated, i need to check that recylerview has more item than single screen ie I have more than items to scroll.
因此,当 recylerview 膨胀时,我需要检查 recylerview 是否有比单个屏幕更多的项目,即我有多个项目要滚动。 I will show in image.
我将在图像中显示。
Also other condition when item is half cut from bottom edge.当项目从底部边缘切半时的其他情况。
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.所以我想知道是否有任何侦听器在RecyclerView第一次完成放置其项目时调用,从而可以设置布局管理器。
Im assuming you have a parent view for your recycler views, eg NestedScrollView
.我假设您有一个用于回收器视图的父视图,例如
NestedScrollView
。 Then you will need to get the height of your NestedScrollView
after it being created in your screen然后,您需要在屏幕中创建
NestedScrollView
后获取它的高度
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然后你可以检查这个
NestedScrollView
高度是否超过你的屏幕高度,你可以在 Activity 中使用windowManager
获取你的屏幕高度
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
因此,在获得
screenHeight
和nestedScrollViewHeight
您可以减去以检查nestedScrollViewHeight
是否大于screenHeight
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.