RecyclerView in Android -- set view gone is useless - android

When I use RecyclerView with LinearLayoutManager which sets orientation as horizontal and then set adapter to RecyclerView. At the same time, I set RecyclerView's visibility as View.GONE.
But a strange thing would happen when I call adapter.notifyItemInserted or any other method like this, the RecyclerView would change to View.VISIBLE.
Why this happened and how can I fix this?

the problem doesn't exist.
I am so sorry that I made a mistake in my app to make Recyclerview become visible.

Related

RecyclerView - how to animate view visibility?

I am looking for way to change view visibility (from gone to visible) inside RecyclerView.
I tried to add android:animateLayoutChanges="true" to my ConstraintLayout (root of RecyclerViews items) and change programmatically visibility of its child.
It works quite well, but first few items are weird - I mean that they completely disappear and show once again instead of animating only visibility of one view. Rest of them are good.
Is there any solution? Do you need any additional informations?
Thanks for help!
You can set a default ÌtemAnimator to your RecyclerView
your_recycler_view.setItemAnimator(new DefaultItemAnimator());

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.

Recycler view in a recycler view

I am looking for solution that solves a problem of a dynamic list that in turn contains a dynamic list of rows.
I have a recycler view which holds a card view that eventually holds another recyclerview. I can see that the parent recycler view is showing up but the child recycler is not showing up.
{{recyclerView{cardView{recyclerView}}}
The getItemCount method is being called but all the other methods such as onCreateViewHolder and bind are not being called.
I have made sure both the recycler views have the linearlayoutmanager implemented and have setFixedSize as true.
I believe it is the issue with your xml layout. Maybe it is not coming in focus hence it is not calling those overridden methods,as recylerview becomes unavailable.Make sure that the padding,height and rest other things are such that the child recyclerview is visible.Actually when I implemented it, I faced the same issue and the reason was my xml layout with the same reason as my second recyler was not visible due to overpadding and margin.
Found the problem. Had to upgrade to a newer version of recycler view. And added wrap content. It started working.

RecyclerView remove animation bug

I have implemented a RecyclerView where I can add and delete items. I want the added item to be added on the second last position and, whenever I add a new item, the animation runs well. That is, the last item moves downwards, letting space for the new item to fade in.
When I remove an item there is a problem that I don't know how to fix. How I want it to behave is:
fade out the deleted element,
move upwards all the items below it.
What actually happens is that, first thing, the last item disappears, and then the rest of the animation takes place. When the items below the deleted element move upwards, the last item reappears as coming from behind a wall.
To me it seems as if the RecyclerView shrinks to the "post-animation" height, and then the animation is performed.
I haven't defined the ItemAnimator, so the DefaultItemAnimator must be the one used. I have watched this video, and overridden the supportsPredictiveItemAnimations method in a custom implementation of LinearLayoutManager, but it doesn't fix it.
I already reported the problem through Google Issue Tracker here
I hope we can get a fix soon! As you say It seems very related to a possible race condition between the measure updates for the recyclerview and the animation when your recyclerview is wrapping it's content to calculate it's height.
This article explains the problem in a really detailed way also.
Perhaps a bit late, but I was able to fix this in my situation by setting the RecyclerView item animator to null, and then in the setList(list) function of my Adapter scheduling a Transition as such:
Transition transition = new AutoTransition();
transition.setDuration(200); // Or any duration you want
TransitionManager.beginDelayedTransition(mRootViewGroup, transition);
where mRootViewGroup is the viewgroup containing the RecyclerView.
This problem is also fixed by setting your layout_height (or width, depending on the scrolling orientation) to something other than wrap_content, but if, like me, you need your recyclerview height set to wrap_content, this might be a solution for you.
Not certain it will fix your problem as well, but I figured I might as well share what worked for me.

RecyclerView smoothScrollToPosition bug

I have a RecyclerView with GridLayoutManager and a button, when i click the button i want to smoothScrollToPosition. My custom view is simply a RelativeLayout containing a TextView. When i run the program on Lollipop everything's fine, i press the button and the application scrolls smoothly to the given position. When i run the same code on pre lollipop devices or virtual machines, i click the button and the app instead of smoothScrolling starts lagScrolling, it scrolls but with so much lag it's not even funny. The same code but with ImageViews instead of TextViews in the custom View doesn't lag, almost at all. Is this a known bug or can it be solved? My code is just a basic implementation of a RecyclerView with adapter but if somebody needs to see it i'll post it.
Please post your CustomView xml and your adapter code.
You probably set your TextView's width to "wrap_content", and then you probably performing TextView setText() inside adapter, causing it to measure the width of the component again each time onBindViewHolder() is called.
You should try changing TextView width to "match_parent" or some static value in dp.
Please take a look at this question

Categories

Resources