如何为最后一个元素在RecyclerView中添加边距? [英] How to add margins to a RecyclerView for the last element?

查看:1043
本文介绍了如何为最后一个元素在RecyclerView中添加边距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个使用RecyclerView的屏幕,并且在RecyclerView上方还有一个小的Fragment.当显示Fragment时,我想确保可以滚动到RecyclerView的底部. Fragment并不总是显示.如果我在RecyclerView上使用了边距,则需要动态显示并在显示Fragment时添加它们.我可以在列表的最后一项上添加边距,但是这也很复杂,如果以后再加载更多内容(例如分页),我将不得不再次去除这些边距.

I several screens that use RecyclerView and also has a small Fragment that is on top of the RecyclerView. When that Fragment is displayed I'd like to make sure I can scroll to the bottom of the RecyclerView. The Fragment isn't always displayed. If I used margins on the RecyclerView I'd need to dynamically remove and add them when the Fragment is displayed. I could add margins onto the last item in the list, but that is also complicated and if I load more things later (ie pagination) I'd have to strip off those margins again.

如何动态添加或删除视图边距?还有什么其他解决方案?

How would I dynamically add or remove margins to the view? What are some other options to solve this?

推荐答案

因此,如果要在RecyclerView的底部添加一些填充,可以将paddingBottom设置为false.这是一个例子

So if you want to add some padding at the bottom of your RecyclerView you can set the paddingBottom and then clipToPadding to false. Here's an example

<android.support.v7.widget.RecyclerView
    android:id="@+id/my_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:paddingBottom="100dp" />

这篇关于如何为最后一个元素在RecyclerView中添加边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆