我有几个使用RecyclerView
的屏幕,并且在RecyclerView
的顶部还有一个小的Fragment
。当显示Fragment
时,我想确保我可以滚动到RecyclerView
的底部。Fragment
并不总是显示的。如果我在RecyclerView
上使用边距,我'我需要在显示Fragment
时动态删除和添加它们。我可以在列表的最后一项上添加边距,但这也很复杂,如果我以后加载更多的内容(即分页),我将不得不再次剥离这些边距。
如何动态地添加或删除视图的边距?有哪些其他选项可以解决这个问题?
4条答案
按热度按时间wljmcqd81#
因此,如果你想在
RecyclerView
的底部添加一些填充,你可以将paddingBottom
和clipToPadding
分别设置为false。oxosxuxt2#
您应该使用Item Decorator。
ohfgkhjo3#
我在Kotlin中使用它来为
RecyclerView
最后一个索引给予余量。oaxa6hgo4#
Item decorator是我的最佳解决方案
用这个Kotlin溶液
那就这样用吧