Prevent RecyclerView item from detaching - android

I have a RecyclerView, one of its item views contains a TextureView. If I scroll this item outside the screen boundaries, the item view will be detached from RecyclerView, which leads to context loss in TextureView. TextureView will be redrawn again, if the item view will appear on the screen again.
My goal is to prevent this redrawing. For now, I see only one solution for this problem - prevent RecyclerView detach its item view. Is there any way to achieve this?

Try to Put this line in starting of onbindViewHolder.
holder.setIsRecyclable(false);

Related

Android RecyclerView scrolls to top when child element is expanded/collapsed

I have a list of elements in a recycler view that are generated dynamically using data binding. Each element has a bottom view that is initially set to View.GONE, however once a user clicks the element and the view is expanded, the recycler view automatically scrolls back to the top of the list. Conversely, if the view is expanded and then clicked again to collapse, the recycler view scrolls to the top of the list again. I have tried keeping track of the ID's of the elements for the adapter (again using data binding), setting focus to the child element when they expand or collapse, and using binding adapters to animate the expand/collapse itself.
My suspicion is that the adapter in the recycler view is receiving a onNotifyDataChanged() alert when the height of one of the child changes, rendering an additional view (still inside one of the children though, not a separate child in the list), and automatically scrolls to the top. Is there a way to override this? Does anyone know what else might be causing the list to snap to the top when one of the elements is clicked -> expanded/collapsed?
So I found the solution to my issue in case someone encounters something similar. I actually ended up finding this answer: RecyclerView notifyDataSetChanged scrolls to top position
and the second solution involving the staggered layout manager was the route I went with, since I want to be able to wrap the content. My suspicions were correct that it had to do with the changing height of the elements in the recycler view. The expandable item's parent wrapped content, so the recycler view was forced to recalculate the size of the item once the expandable portion appeared/disappeared (at least that's what I got out of it).

Animation on part of item in recycler view

I am trying to implement a recycler view which will show items with rating and when ever rating changes it will flip the current rating with animation.
I am doing this on onBindView. The problem I am facing is, onBindView is called even view holder is partially visible ie. rating view is still not on screen and as a consequences it animate before its time.
Any help is appreciated. Thanks in advance.
You can listen for scroll events and determine which items have transitioned between non visible and fully visible.
Register a scroll callback with:
RecyclerView.addOnScrollListener
If you are using a LinearLayoutManager your callback can use the following methods to determine which items are visible:
LinearLayoutManager.findFirstVisibleItemPosition
LinearLayoutManager.findLastCompletelyVisibleItemPosition
It is up to you to track the changes in item state between non-visible and visible.

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.

Remove item animation from Recycler View with scroll

I have some problem with animation on RecyclerView
I have chat list with lot of messages. Each message is removing with delay (20s) and animation fadeout(0.3s). All work fine but it look strange sometime. Because if message is removing then all item below going up during first item is removing (fadeout). It looks like cumulative views on first position.
I am thinking about start animation before remove item. But it is not good idea. Also I thought about combining removing animation with scrolling the removing view.
One thing you can do is animate/collapse the height of the item view from its full height to 0, then remove the item from the adapter and refresh after that animation is complete.

Animation in ListView item doesn't work after scrolling

I have animation in one listview item. After scrolling list when list item with animation started not visible I am scrolling back to the listview item with animation but animation doesn't work anymore.
getView() method :
iv.setImageResource(R.drawable.anim);
iv.requestFocus();
((AnimationDrawable) iv.getDrawable()).start();
?
UPDATE:
Is it wrong question or there are not any ideas?
You are assuming that every time the view is been scrolled(or become visible to you), the animation will start playing. But it's not true, the view can be not visible an yet be in the memory, so when you are scrolling it and it become visible, the getView() method will not be called. This is why it is a bad practice to put animations inside a list. I suggest you to implement the entire view by yourself if this is something you most to do.

Categories

Resources