I'm trying to create a scrolling sheet of paper containing a RecyclerView. To achieve this I gave each item a background and its own shadow. When you look closely you can see where the items meet because the shadow is slightly darker. The left list also has a divider which has the wrong color because the shadow is behind it.
I was wondering if there may be a better solution for this. You can't set the background and shadow on the RecyclerView itself because then it wouldn't scroll of the screen as the bounds don't change. You can't use a LinearLayout+ScrollView because this would break when there are too many items.
I would say just use CardView and set useCompatPadding to true in your XML so that it adds enough padding for the shadows not to overlap.
Alternatively, you can add margin to your items.
Another option is using an ItemDecorator that does not draw anything but returns enough margin for shadows in the getItemOffsets method.
Related
I have created a sample project that can reproduce this issue.
Expected Result
When I scroll the bottom RecyclerView upwards, the top RecyclerView collapses
When I scroll the bottom RecyclerView downwards, the top RecyclerView expands
Observed Result
When I scroll the bottom RecyclerView downwards, the top RecyclerView does not expands
Additional information
Try to hold your swipe when the top RecyclerView collapses at the half, and then swipe down. You can see half of the top items being cut.
This only happens for the collapsing View being/includes a RecyclerView.
GIF
(Ignore the changing color - it is just a result of compressing GIF)
Question
Did I do anything wrong or it is a MotionLayout bug?
I came up with an alternative solution.
For easier communication, I will use rvTop for the top RecyclerView and rvBottom for the bottom RecyclerView.
Instead of "shrinking" rvTop, the idea is to "hide" it instead.
So instead of let rvBottom constraint to the bottom of rvTop, we need to introduce a new invisible line in between them, and use MotionLayout to animate this invisible line upwards, while keeping the alpha change of rvTop.
In order to do this, we have to make rvBottom opaque, otherwise it will overlap with the fading rvTop.
I have updated the code in the sample project to demonstrate the changes.
And the effect is:
EDIT:
Another alternative is to remove rvTop's constraint to top of parent after the transition.
Yes, this will make it simply scroll with the rvBottom; but we can add a little bit of translationY to make it "scroll slower than rvBottom".
This can handle the case where you cannot make rvBottom opaque, for example the page itself uses a gradient background.
The effect looks like this:
Hi I need to implement the layout as attached in pic. I have tried this StackOverFlow answer
but the resultant view get created as attached below
I need that bottom right corner to be above next cell of recyclerview.
Please suggest how can make top of the cell below previous cell.
It looks like you're close. The problems you're seeing here are:
The offset you're using in the item decorator from the example you used isn't large enough - hence the black gaps
The order in which your linear layout manager is stacking your views is from the top, which means that the row below will draw over the cell above.
To fix this, first, add a bit more offset to get rid of the black gaps.
Second, call setReverseLayout(true) on your LinearLayoutManager (can also be done via the constructor) - this will make it draw the bottom items first, so that the cells will draw above the cells below.
Also, you might want to play around with the elevation of the views to get that neat shadow effect, making sure that a row at index N will have a higher elevation than a row at index N+1. You could do this by calling myView.setElevation((getItemCount() - position) * SOME_DP_AMOUNT) when binding each view in your adapter.
I would like to know if it's possible to have the add/remove animations not overlap the divider like in the following video:
https://www.grokkingandroid.com/wordpress/wp-content/uploads/2014/08/recyclerview_animation.mp4?_=1
I am unsure as to how I can make the divider be bound to the item and not the view. Any help is useful.
Check the divider in SupportV7Demos app in AOSP. Basically, you should consider View's translateX/translateY properties when positioning your dividers.
Currently, I have an Activity, with a ListView on the top, and LinearLayout on the bottom.
When a row in my ListView is scrolled and the row is partially shown, it looks like this. (LinearLayout is the one with Value wording)
However, I wish to have the following effect.
It seems that LinearLayout adds a "glooming layer" at the bottom of the ListView. - I am sure this is not optical illusion. :)
How I can achieve such an effect?
Add
android:requiresFadingEdge="vertical"
on ListView will solve the problem
One of the ideas that comes in my mind right now is to create a shape with a transparent gradient color. Then create a View above the LinearLayout and put the Shape as the background.
Another idea is to put a transparent image, instead of shape, above LinearLayout.
i was requested to make in android a view that groups several items like checkboxes or text views in vertical rows, separated by transparent dividers while the background is with a certain alpha level and the edges are round.
I thought of two solutions and i hope for some feedback on good\bad or other solutions if you got'em.
just use regualr linear layout but have a single style A that uses a 9 patch as background, includes padding,margins and whatever i need to make it look like what i want. i then create another style A.up and A.down that represents the upper most and lower most items that will use a different 9-path with round corners.
inherit from linear layout, in the onMeasure and layoutChildren add to all the children some kind of space between them, i can create new attribute for it that can be customized in a style. i can override the dispatchDraw to paint the background for each view before it draws so i can paint my round borders, my only demand will be that each View added to this layout will have to be with transparent background.
So what do you think ?
Eventually i decided to use a List with customized divider.
It looks good, however a list got a very nasty bug when it comes down to items with states like buttons and clickable textViews,
you get no focus for the item and don't see the ornage bar
you don't seem to get the evnets flowing to the children of the View in the list.
I'm notsure how to resolve that one, i've seen numerous mails about it in the developres mailing list and here, most saying don't put statefull objects in a list.
So it mist not be the solution for me.
Nest thing i'll try is extending the normal layouts to have a bar in their bottom and use regualr linear layout with round corners drawable.