Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show exactly ten rows in RecyclerView

I would like to always display exactly ten rows in a RecyclerView. RecyclerView does not have a configurable setting for this. One approach is to calculate the size of each row. I would like the table to take up half the screen and always show 0..10 items within that area. If more than 10 items the user would scrooll to see the items. Right now the default behavior of RecyclerView seems to be to keep pushing everything down as it grows.

like image 266
StevenAbroad Avatar asked Jan 25 '26 02:01

StevenAbroad


1 Answers

@Override
public int getItemCount() {
    if(list.size()>10){
     return 10;
 }else{
 return list.size();
}
}

In your recycler view adapter class return get item count to 10 if size of array or list is greater than 10

like image 135
Tomin B Azhakathu Avatar answered Jan 26 '26 17:01

Tomin B Azhakathu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!