I have a viewpager2 with customTransformer that works fine, the issue is i can't define margin between items so it only shows 1 item at a time (i don't want to see the preview of the swiped item) , i tried with setPadding(12,0,0,0) and what it actually did ,it cut from the width of my item. i couldn't find how to use margin in itemdecoration so it could set a larger margin between th eitems, anybody have an idea ?
I ended up editing my own custom hinge depth page Transformer by setting up the spacing needed for between items to translationX = spacingValue
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've RecyclerView with LinearLayoutManager and horizontal orientation. I want to add it zoom in/out functions(like Trello Android app). I changed the items' scale:
itemView.scaleY = 0.7f
itemView.scaleX = 0.7f
Then space appeared between items. How to remove these spaces and place items one by one without space? This is how it looks like now
Horizontal recyclerView (DiscreteScrollView library) with scaling set to 50% between selected view and others doesn't keep spacing the same. Example below shows that spacing between 1/2 and 4/5 are more spacious than views next to currently selected item on center. It happens gradually by scrolling, for an example going from item 3 to item 2 will be moving item 3/4 apart from each other when onScroll is happening.
spacing between items example
I Thought about checking the current width of view when onScroll is happening and programatically reduce the left/right margin by applying new layout params so the space would stay the same.
Trying:
override fun onScroll(
scrollPosition: Float,
currentPosition: Int,
newPosition: Int,
currentHolder: CurrencyAdapter.ViewHolder?,
newCurrent: CurrencyAdapter.ViewHolder?
) {
val layoutParams = currentHolder.layout.layoutParams as ConstraintLayout.LayoutParams
}
}
produces
ClassCastException: androidx.recyclerview.widget.RecyclerView$LayoutParams cannot be cast to androidx.constraintlayout.widget.ConstraintLayout$LayoutParams
1. Is it possible to manipulate layoutParams from within viewHolder?
2. Are there any other options to set fixed spacing?
EDIT:
adding DividerItemDecoration shows better where the problem is coming from:
DividerItemDecoration
3. Is ItemDecoration the right direction for fixing the issue then?
I currently have a recycler view that has a list of CardViews.
When I click on the card I want to be able to expand the card (change only the height). This is working fine by setting the new height to the card with an animation.
The problem is that when I click to expand the card, the width also shrinks to less than half the width of the screen. If I scroll the view away and come back the width is set correctly. Every time I try to expand the height, it expands to the right size but the width shrinks.
Is there something that I'm supposed to do to expand/collapse a card in a recycler view and not have this side effect of also resizing the card width?
I tried only setting the height in a valueAnimator and that works for the expansion.
I tried to set the width programmatically at the end of the animation to match parent but that has no effect.
for better solution pls share code with us, until that.
check your xml codes for any Wrap content value for width.
It will solve your issue.
Is it possible to make four gaps' width the same?
I tried to use ViewTreeObserver.addOnGlobalLayoutListener() in ItemDecoration.getItemOffsets(),but the view displays before the value returned,and the gap was 0.
The gap image here
Thanks for your help!
Yes, First you can set layout_margin on recycleview.
After set margin on recycleview raw.
It's work.