I have horizontal RecyclerView with 10 items with square fixed size and with attached LinearSnapHelper.
I want to see an integer number of items in the list depending on the width of the RecyclerView.
Example:
I think that I have to somehow calculate the width of the RecyclerView and find how many whole items will fit into the visible part of the list, and the remaining space should be reserved for spacings between items. After that, user scrolls items with SnapHelper. Thanks in advance for help!
EDIT:
I do not want to show all the items from the list at a time, but only those that fit into the visible area of recyclerview and calculate spacings dynamically between items
Related
I have a listView that is populate via a RSS feed. The height of each item on the ListView can vary depending on the length on the content. Is there a way to only add enough items to the listView to fill the screen (the listView has a fixed height).
For example if each item only has one line of text I can fit 7, but if they have two lines of text I can only fit 5. I want to be able to programmatically decide when to stop adding items. I don't want the ListView to have to scroll.
EDIT
Let me rephrase. I don't want to just solve it but scrolling down. There may at some point in the development be content that gets added below the screen and requires scrolling but even in that case I don't want half an item showing at the bottom. Basically I don't want broken/half items showing at the bottom, if it's on the screen it should be the whole item that is showing. If not it should be below the bottom of screen.
Try using a normal Linear Layout and when adding the inflated row, override the onMeasure to know if it fits on the screen.
I've a recycle view inside a fragment (max item will show in list is 5), I want to set the fragment container size according to the number of items showing in list,
What I want is user shouldn't need to scroll the list to see all the items?
A RecyclerView is intended for showing many items in a scrolling list.
That's where it gets its name from. It efficiently Recycles the Views for items that have been scrolled off screen.
From what you are describing, you are only ever showing a maximum of 5 items and you want them all on the screen at the same time, so you don't need a RecyclerView.
Just add your items to a LinearLayout and set the layoutHeight of each item as 0dp and the layoutWeight of each item as 1. That will distribute the items evenly across the full height of the LinearLayout.
Edit
If you want the fragment to adjust it's height according to the number of items, then set the height to WRAP_CONTENT for the fragment container, LinearLayout, and each of the items you add to the linear layout.
In an app that I'm developing I need to display a GridView with items that depending on its text (more than one line of text) may be of different height and I want to avoid that the items are shown with different heights since it's quite ugly.
When the text is only one line the GridView the items in the row are displayed properly but when the text is larger than one line they are shown like this:
How I can avoid this behavior and set the highest height of an item of a row as the height of all items of that row?
I'm trying to do menu footer which have 10 button and can horizontalscroll.
So i use recyclerview to do that.
What i want is this footer by default always show only first 5 items in screen with all screen size and user can scroll this.
So i have a question
How to show fixed number of items of rows in a recyclerview ?
How to set distance of 2 items in a list recyclerview ?
Thanks for read.
I have a listview, the listviews width and height should be set to match parent. So, if the listview is fully stretched and has only 2 items in it, they are at the top of the listview and on the bottom is too much useless space. I want to know, if it is possible to center these 2 items in this listview vertically, if yes, how?
List height depends on the height of the list item, that is populating the list.
If you have only two items in the list why don't you simply use a Linear Layout instead with weightSum?
Anyway, if you want to achieve the result you requested in your question you have to get the display height using method
getResources().getDisplayMetrics().heightPixels in activity context.
After that you need to set the height of the list item to the height you retrieved earlier divided by 2.
And also set gravity to center_vertical for the textviews in the list.