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());
Related
I'm a newbie when it comes to Android coding, so please bear with me. I looked this up for quite some time before posting here, so that I don't waste your time with a question that I could have answered myself through some research.
Here's my issue: I have a CardView and I want the items to start popping up from the bottom instead of from the top. For example, something like this.
I found out that you can do this via the "stackFromBottom" XML attribute in ListViews and GridViews, but it doesn't work for CardViews.
I also noticed that you can change a ListView's gravity, but CardView doesn't seem to support that either.
So is there a simple way to populate the CardView in this way?
Any help would be greatly appreciated.
CardView can hold only a single item, so in this case you can have a ViewGroup inside the CardView , and add those items to the ViewGroup.
I'd suggest ConstraintLayout and constraint the first view to the bottom of the layout and next views are constraint to their bottom views so that you can fill them from the bottom.
If your list is big.. You can wrap the ConstraintLayout with ScrollView so that the items can be scrolled; or replace the entire approach by a RecyclerView
Since you said that you are using a recycler view you could use a simple property to accomplish what you need.
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.
I'm currently using a regular RecyclerView with GridLayoutManagerwith different spanCount depeding on the viewType for an Android TV app. All is working decent but I have 2 issues:
If you long press the dpad down to scroll fast between the items sometimes the focus is lost to a view that isn't a child of the RecyclerView.
How can I tell the RecyclerView to keep the current focused view in the center of the grid?
It seems that the issues listed are fixed by using the VerticalGridView from LeanBack library but the LayoutManger that it uses is internal and doesn't support spanCount.
For a regular RecyclerView,
I had to specify: android:descendantFocusability="beforeDescendants"
And also android:nextFocusDown="#+id/recyclerviewId" is set to send focus to RV itself.
The only solution I see is a key listener to select item to position currentPosition + spancount.
Recycler view works fine with android TV.Possible solutions you can include are:
1.add focusable and focusableInTouchode to view.Add focusListner through the code and request focus each time when the view is clicked.
2.To keep Recycler View focused item in the centre you have to override layout manager just like this example.
RecyclerView smoothScroll to position in the center. android
or
use layoutManager.scrollToPositionWithOffset(position,offset) where position-focused view position and offset is the recycler view width/2.
You can try to check this workaround for the bug with RecycleView focus scrolling when navigating with d-pad.
Here is the SO question for that.
The problem here is that the GridLayoutManager uses LinearLayoutManager's implementation of onFocusSearchFailed() which is called when focus approaches the inner border of RecyclerView. LinearLayoutManager's implementation just offers first/last (depends on scrolling direction) element. Hence focus jumps to first/last element of new row.
So, maybe this workaround will solve your issue or give you an idea on how to solve your problem.
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.
I'm implementing a listview that looks like this :
So basicly I have a listview, with a headerview. My problem is to set the space between the headerview and the rest of the listview. If anyone has a clue, thanks :)
To set a gap below the header view you can just add marginBottom to the header view. That should do it. But like Pauland said, never ever EVER put a listview inside a scrollview. You are basically placing two vertical-scrolling views ontop of each other and Android can't tell which one to scroll when the user swipes!