This is a question regarding the use of Android Transition API.
I am trying to animate the height change of a list, just like a dropdown menu.
I tried 2 approaches
Use a RecyclerView and animates its height change
Use a ScrollView > LinearLayout hierarchy and animates ScrollView's height.
The 2nd approach works perfectly.
But the 1st approach has a serious glitch - when the collapse transition starts, items disappear immediately.
By looking at the below GIF you can observe clearly the difference:
To be exact, items' visibility changes at the moment I change RecyclerView's LayoutParams, without waiting for the transition to finish, whatever it is expanding or collapsing
Code
I have created a minimal project on Github.
If you just want to look at the code, here is the MainActivity.
Question
Is it possible to achieve ScrollView's effect with a RecyclerView?
If yes, how?
My Idea is to do the transition of all the recycler view rows individual rather than the whole RecyclerView:
So when collapsing iterate through each ROW of a RecyclerView and do a transition. Remember to check for null if some rows are recycled they may return null. So after that collapse the whole recyclerView.
And like wise for the expanding do the same for the views.
This issue is cause by RecyclerView has many views with it but Scroll View has only one View nested in it.
Related
I have a LinearLayout inside a ScrollView and I want to create the ilusion of endless scrolling by removing the views that are not visible and putting them as the next elements in the list (basically i do a linearlayout.removeView(viewOutOfScreen) and then linearlayout.addView(viewOutOfScreen). The problem is, every time this happens the view that is currently visible ends up in the top of the ScrollView. I tried doing a scrollView.scrollTo(0, -viewOutOfScreen.contentHeight) and it kinda works but the transition generates an horrible tearing artifact.
Also I'm not able to use RecyclerView given that the views are WebViews with very specific settings and executing js, so i nedd to reutilize/reposition them manually (cant't create more than i initially have).
I recommend using a nested RecyclerView because, it does exactly what you are trying to achieve manually. It recycles views which are out of the screen.
Also I'm not able to use RecyclerView given that the views are WebViews with very specific settings and executing js, so i nedd to reutilize/reposition them manually (cant't create more than i initially have).
So what if they're WebViews? You could just manually cache the views you want to display (ignoring the "recycling" part of RecyclerView) and return the View you want for each index instead of letting the RecyclerView delete and recreate them.
I am experimenting with a RecyclerView and it currently displays four CardViews vertically on the screen. Using an adapter, I am able to resize each CardView's height equally in the space given.
What I'm trying to accomplish:
On click, I would like the selected RecyclerView child to expand to fullscreen. Currently, I can programmatically set the height and expand the selected CardView dimensions, but the other CardViews after it are pushed down off-screen. How can I have all the selected CardView positioning become absolute, and lock the other views positions and expand "over" them? Is this the proper approach, or should I be looking into shared-element transitions or something else?
Side-ask: Is there a way to control all top/left positioning of RecyclerView children in an adapter?
The comments above seem to be correct - after looking into shared transitions, I found numerous examples performing the exact behavior I described. Crediting #AmratSingh since he answered first.
If it helps anyone, here is the one I am following currently: Michael Scammell - Shared Element Transitions
This one in particular: Shared element transitions within a RecyclerView
I have a vertically scrollable list using a RecyclerView. The layout I'm trying to implement is that when you scroll down far enough and reach a specific item, if you keep scrolling past this item it will stick to the bottom of the screen while the rest of the list continues to scroll behind it. Currently it's implemented by having a scroll listener on the RecyclerView and manually adjusting the position of the sticky view as required, but this is hacky and hard to build on.
Is there an easier way to have this kind of layout? I am currently investigating using a CoordinatorLayout but I'm not sure if it's the right tool for the job.
You can accomplish this using a CoordinatorLayout with a custom behaviour. The behaviour should be applied to the sticky view and make it appear/disappear as the RecyclerView scrolls. You have to override onStartNestedScroll in your behaviour to return true to receive calls for scroll changes.
I'm postponing transition between two fragments which both contain RecyclerViews with the trick of creating a fragment, hiding it and only show it when the RecyclerView is ready...
Like explained very well here: https://halfthought.wordpress.com/2015/06/04/postponing-fragment-transitions/
My problem is, that this does not work, as the views of the recyclerview seem to not be layout out correctly when the RecyclerView is predrawn, this results in wrong transitions (in my case the child views of the RecyclerView calculate their sizes in onCreateViewHolder and this MUST finish before the transitin starts). Now I adjusted my adapter in that way that the adapter reports when all relevant views are bound, so that I can continue the transition, but this does not work, as then the RecyclerView does not start laying out it's child views, probably because the RecyclerView is not visible yet...
Can I somehow force the RecyclerView to layout it's children even though it's hidden? Any other suggestions?
Am trying to create a page with a scrollable list. Features would be a normal list to remove item by clicking on it. Number of items in that list are limited and added dynamically by user. You can consider a to do list as example. Now which would be a better approach to implement it? Recycler view with data bound to its adapter? Or the normal linear layout with items added as children at run time?
My current implementation is recycler view. But,I found it lagging and animations are not performing well. So a linear layout is auto animated by specifying it xml -- by setting animate layout changes to true.
FYI data is local and syncs in background.
Never use a LinearLayout for anything longer than a single screen. The whole point of ListView and RecyclerView is to efficiently reuse views instead of needing to hold things in memory when they're not visible. Maybe you can refine or reask your question so people can help you with whatever difficulty you're having with animations, rather than avoiding the issue.