Add Padding Bottom in RecyclerView Android
Hello guys, on this week I want to share something special but I think it's useful for us. It's understable from the title of this post. But I will explain a little bit why I used padding bottom for my RecyclerView in Android. I have something called floating button to add my item in RecyclerView. It will be bad If I scroll to bottom and my floating button above item RecyclerView. I can't see clearly what text item in RecyclerView.
You can see from picture above, I've marked a rectangle in picture above. Imagine if there's no padding bottom. It will truncate my RecyclerView items and it will make my app looks when in interface. So I think I need to have padding bottom in RecyclerView. But How do I do that ? Is it hard to implement ? Or Is it just a few code lines.
I want to make "adding button" always be bottom right on my view and I don't want it to stack above RecyclerView. So the easy solution is to add padding. I changed my xml file layout and I added paddingBottom to 75dp and clipToPadding to false. I added these in RecyclerView widget as you can see below.
This is the implementation code, notice the comment I added :
There's nothing to do with java or koltin class. It's only layout xml that need to change guys. I intentionally share my full layout so basically It will be like above picture. TextView empty_view will be shown when no items is in RecyclerView.
I haven't tried on ListView, but I think it will work. Thanks for visiting my simple. I hope I can always share my experience to you all guys. If you have any problem with iOS or Android you can ask me through email or comments. I'm glad I can give you advice or solution. Thanks.