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.
Related
I have a problem with recyclerview items width:
i already looked through android docs and stack so i think, there is no solution to this problem.
i have an ordinary recyclerview with a horizontal gridlayout
sorry, but i dont have enough reputation to embed pictures
Picture of recyclerview
and i want the items of it being shown next to each other, but I want to make the width of the items depend on the width of the parent (in this case, the recyclerview width used in the other fragment).
I can show you what i want by using a fixed value (in this example 200dp)
Picture of the solution I want, but here a fixed value for width is used
However if my constraint of the item is set to "match parent" like here:
Picture constraint set to match parent
The result is, that the width of the items seen in the phone always depends of the width of the recyclerview. in my case its cut nearly in half:
recyclerview cut in half
also android studio only allows one view as a top level layout, so i cannot use a guideline that is set to any %
possible solution to that?
If you have width of recycler view (in pixel not dp), just divide it by number of items in a row, and in your adapter in "onBindViewHolder" method set item width. this solution is when all of your item has same width.
In addition for height of every item use WRAP_CONTENT.
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!
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
I use recyclerView with LinearLayoutManager.
When I try to show an item with a height bigger than the height of the recyclerView, I have an empty view.
I fix the height of the item below the height of the screen every things works, but when I use a fixed height like 900dp on item, I have an empty space.
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.