Fragment Transition - postpone until RecyclerView has laid out relevant elements - android

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?

Related

Impelement two recyclerview in one screen

How can I implement this kind of UI, where we have two recyclerViews. One scrolls horizontally and the second one vertically. when the second one scrolls first one also scrolls top together.
I tried to implement using NestedScrollView, but I had to make second recyclerView height wrap content which causes recyclerView not recycle.
The second way that I tried was having one recyclerView. And adding horizontal recyclerview as a header. The problem was to save header recyclerview scroll state when navigation. And there had been crashes when loading next page (paging 3) in header recyclerView.
The question is: Is there any optimal solution for this kind of ui?
In cases, Like this, you don't have to use 2 RecyclerView and you also have to avoid using RecyclerView insideScrollView. instead of this you have to use one vertical RecyclerView with multitype view Adapter.
in this way, you are going to have 2 different ViewHolder one of them is a horizontal recyclerView (your top item) and the other one is your other items.
for learning multitype adapter you can see this:
How to create RecyclerView with multiple view types
and for a horizontal recyclerView inside a vertical RecyclerView you can see this :
https://medium.com/#ashishkudale/android-list-inside-list-using-recyclerview-73cff2c4ea95
you have to combine these 2.
I could not understand the meaning of "header" where you said "adding horizontal recyclerview as a header" but if you did what I told and the problem is the state of inner Horizontal recyclerView, I think probably you are calling setAdapter method of horizontal RecyclerView in OnBind() method of your vertical recycler view, it is a common mistake that I have seen in many tutorials.
if you have done this mistake , try to call setAdapter of your inner recyclerView in the constructor of its viewHolder and just update the list using yourHorizontalAdapter.notifyDataSetChanged() in onBind() method of VerticalRecylerView,
and if its not the case and your recyclerView is completely destroying see this link :How to save RecyclerView's scroll position using RecyclerView.State?

Why RecyclerView items disappear immediately when using Transition API?

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.

Nested RecyclerView; inner child steals focus

I have one RecyclerView as the "main" stream of things. One of the things could be a RecyclerView with 2x2 grid of items.
When I launch the activity, create the fragment, create the RecyclerView, etc. in TalkBack mode,for odd reason the child of the inner RecyclerView gets the focus (its content gets read instead of the activity's title like normal -- as in other places that do not have this nested RecyclerView structure).
I must be missing something obvious.
I've tried calling setFocusable(false) on that child (confirmed using Hierarchy Viewer that focusable=false) yet TalkBack still focuses on it for no obvious reason. My code doesn't explicitly request for focus.
Any pointers are greatly appreciated. Thanks!
Try android:descendantFocusability="blocksDescendants" on its parent or parent of the parent it worked for me on a similar issue

Vertical RecyclerView containing nested RecyclerView

Structure of my Android app is forcing me to create Vertical Nested RecyclerView inside Vertical Nested RecyclerView because of the pre-drawing all nested items inside every RootRecyclerView. The View of RootRecyclerView has approximately 5 - 10 views and the View of InsideRecyclerView consists also from 5-10 views. There is not necessarity for scrolling this ChildRecyclerView, because all scrolling is handled by RootRecyclerView (same term as Nested RecyclerView)
I have two options:
1. ChildRecyclerView, that will predraw all child items when the root item will reached the screen (it lags, but the result looks good under the 30 child rows)
2. Join the Root+Child View, remove Child RecyclerView and the all logic will be handled in the Root RecyclerView. - i tried this, also used ConstraintLayout, so the whole layout was only 1-LEVEL, but it was still laggy, even if I set Visibility of half of the views in this layout. I also setup setHasFixedSize(true), tried to use Cache methods of RecyclerView, initialCacheItemSize and so on.
So do you have any ideas, how to solve this problem? Did somebody of you met with this kind of problem? You could also imagine the case of ChildRecyclerView inside another ChildRecyclerView that is inside RootRecyclerView.

Adjusting fragments height according the pixel position scroll on a list inside one of the fragments (Android)

Ok, I have a LinerLayout vertical in which there are three fragments, lets say: HeaderFragment, SubHeaderFragment and ListViewFragment (fragment with listview in it). These are put in the layout in this order, width set to match_parent. The header and subheader fragments have a defined height, lets say 100dp each. The list fragment's height is set to wrap_content.
Now, what I want to do is that when the list fragment is scrolled down, the SubHeader fragment should loose its height (according to the amount scrolled) until it disappears and the user checks the list. If the user scrolls back up to the beggining of the list the SubHeader fragment should get its height back, again according to the scrolling.
This can be seen in several Apps, for better use of the screen size.
I have researched quite a bit, but I found no simple solution to this. One would be to keep track of the scrolling position of the list and reset the heights dynamicly while this is done. Which is trouble because as far as I know the scroll position for the list must be calculated and I am dealing with fragments that have no layout params.
Another idea I had was to put the SubHeader and the List Fragments in a scrollview within the linear layout, but that destroys my list within its fragment and people say it shouldnt be done due to bad performance.
Is there a decent simple solution for this? Thanks for any help in advance!

Categories

Resources