I have a horizontal recycler view, shown on a card within a vertical scroll view.
I require the width of the recycler view and have tried using the following code:
recyclerView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED)
val width = recyclerView.measuredWidth
This gives me the entire width of the scrollable area, rather than the visible width of the recycler view's bounds. recyclerView.width evalutes to zero.
Any suggestions of how to get the visible width of the recycler view element would be hugely appreciated!
Related
enter image description here
I dont understand parent,width here wikk it be width of RecyclerView or screen or an item (1 viewHolder) is there anyone explain it to me Thanks
I Tried and it seem to be width of RecyclerView
onCreateViewHolder() creates a structure that hold the view used by a single item in the RecyclerView. That view will be a child of the parent and, in the code you posted, parent is the RecyclerView, so parent.width is the width of the RecyclerView.
The RecyclerView's width in comparison to the screen width depends on how the RecyclerView is defined.
Main target is to make grid layout like Google Meet or What'sapp group call
If there is a single person it should occupy all the space
Single item getting all space
All the items should be equally arranged and with equal height and width and restrict item to move out of recycler view
Auto resize image height and restrict recycler view scrolling
I am creating a recycler view and I have 2 types of itemviews in it. Each item view would have different widths(55dp for one and MatchParent for the another). If I create a recycler view with first 4 rows having width 55dp and the next 2 rows with width MatchParent, do you think my entire recycler view would have same width throughout? Or will it be 55 width for first 4 rows and MatchParent for the last 2 rows?
Please note I have set the width and height as wrapContent for the recycler view and using staggeredGridLayoutManager with single column and vertical scroll.
I only want a single column vertical scrolling recycler view with different widths at each row.
If you can imagine, it should look like an L - shaped recycler view.
Yes, it is possible to have items in RecyclerView to have different height and width.
You should give wrap content for both list item and RecyclerView
Is it possible to have a nested RecyclerViews with following criterias?
The outer RecyclerView is attached programmatically near the top of the view hierarchy of the Activity
The outer RecyclerView is scrollable
The inner RecyclerView lives inside a custom view which is also attached programatically
The inner RecyclerView has a vertical GridLayout with ImageViews
The inner RecyclerView has width match_parent and height wrap_content
The inner RecyclerView is not scrollable
The inner RecyclerView can displays all it's elements by scrolling the outer RecyclerView
The items inside the RecyclerView are recycled correctly
I am trying to build this but the last two criterias are not satisfied. If I have more than 30 Images (GridLayout has 3 columens, so I have minimum 10 rows) further images are not displayed. And if I open the HierarchyViewer I see that the RecyclerView contains all the inner ViewHolders so nothing is recycled, even if i scroll down.
Furthermore I have questions towards the Images within the grid of the RecyclerView. want to calculate their width dynamically and the images are loaded with Glide Library. I make a request to a server which gives me the images in the right width, but the surrounding ImageViewa have 2 dp less than the images themselves. I have a grid spacing of 8dp. I calculate the width of the images(to be requested) with this formula:
imageWidth = (screenWidth - 2 * horizontalActivityPadding - 2 * spacing) / 3;
This should work for a GridLayout with 3 columns. But then the imageWidth has 90dp and the ImageView's width becomes 88dp. This is because I get a spacing after the 3rd column. But I only calculated twice the spacing so I expect to have this spacing only
between the 1st and the 2nd column
and between the 2nd and the 3rd column
but not after the 3rd column
What may be the reasons for
my RecyclerView problem?
my image spacing problem?
I'm writing my custom view and I would like to make it the same width as parent is. And parent is RecyclerView which scrolls horizontally. So I receive widthMeasureSpec in my onMeasure method with size = 0 and mode = UNSPECIFIED.
So how do I know parent's width ?
Thanks.
Technically, width is infinite because it scrolls horizontally. If you want it to have the same width w/ RecyclerView, use recyclerView.getWidth(). You can use the RecyclerView instance passed to onCreateView.