In our fire tv app, we are using a nested recyclerview where every vertical item have a horizontal row as a child item like playstore design.
Scrolling with dpad working fine normally but when i hold the right key for few seconds, item start scrolling very fast because it gets many events & within few second focus goes to the next random row even current row has items to scroll. So this whole problem happening in horizontal scroll(child recyclerview). I have already tried many solutions like this, this, this.
Also tried the custom layout manager, custom focus layout & other approach like slowing down the recyclerview scroll etc approach but all not working.
As far as I know, this happens at the moment when the last item is in focus, and the next item is not visible, that is, the ViewHolder has not updated the data of the first cell, so it is not clear which element to show next as if the list has ended.
You need to make sure that at least the edge of the next element is always visible on the screen.
Maybe you should play with the cell size or divider.
Edit:
The secret is to use the leanback library. It isn't lost focus!
Your gradle:
// Leanback support
def leanback_version = "1.2.0-alpha01"
implementation("androidx.leanback:leanback:$leanback_version")
Change in the layout from RecyclerView to HorizontalGridView (VerticalGridView)
Change in the Fragment import from RecyclerView.widget.GridLayoutManager to androidx.leanback.widget.GridLayoutManager
It works very fast for me and the focus no longer jumps.
Here a good article with animations but little outdated
Related
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 am creating a custom scroll inside RecyclerView and I did most of the work already but now I came to hopefully one of the last problems.
On scrolling, I am expanding/collapsing rows as they move up or down. It works fine until I reach the bottom of the list. Two items remain in their normal state because I can no longer scroll down and therefore they will not expand.
My question is, how can I scroll under the recyclerView when I reach the bottom? Do I need to implement onTouch listener and do the work from there? Or is there something in RecyclerView that can help me create the underscroll?
You should be able to expand them in onOverScrolled, as that will be called at the correct time to trigger their expansion.
I want to be able to scroll a RecyclerView behind a keyboard. The issue is that if I have say more than 5 items in the RecyclerView.Adapter, and assume that each item might have a height of say 100dp. I want to be able to scroll the RecyclerView down with the keyboard still up and be able to scroll down to be able to see the first item in the RecyclerView.
In iOS you can set something called a contentInset on a NSTableView and that gives you extra scrolling space below the list. I am looking for something similar for the RecyclerView so far, there isn't much to go on.
INITIAL STARTING POINT
WHAT HAPPENS (Can't scroll down anymore)
WHAT I WANT (be able to scroll down)
I need a component that works like the picture below but I'm having trouble coming up with some kind of decent solution that works.
I want the list to have a center locked selection but being scrollable with the d-pad. This is for an application running on a TV so no need for touch scroll. So when pressing down on the remote d-pad the list will scroll and a new item will size up and the current selected one will size down and the new selection will still be in the middle.
I've tried doing this using a ListView that I extended and programmatically scrolling when pressing down or up. On scroll finished I called notifyDatasetChanged() on the ListView for re-inflating of the childs and in the ListViews adapters getView() I made the animation of the view located at the current selected position.
This is not optimal since I need to call notifyDatasetChanged(), which re-inflates all visible views, for the animation to apply. The UI becomes laggy when doing this and scrolling fast. It's also not possible to make som kind of compress animation when current selected item goes out of selection. There is also some trouble with the end items (read views) such the first or last in the list when doing animation of them, the may sometimes go out of screen.
I think that his must have been done before and maybe I'm missing it when searching for an answer.
Have anyone done something similar or do you have some suggestions of how this can be achieved? Maybe I'm just starting of with the wrong component here..
Regards,
Kristoffer
I'm working with a rather large layout that includes a ListView and a LinearLayout beneath it as a footer. I first tried to wrap this in a ScrollView to make the whole layout scrollable, but ran into problems due to both the ListView and the ScrollView being incompatible with each other since they both have scrollable features. So, a workaround was to include the LinearLayout as a footer to the ListView.
Now, in the LinearLayout, I have buttons at various places that the user can click to return to the top of the page. The behaviour I am getting from this is odd, to say the least.
If I have not scrolled down too far, the buttons function normally. However, if I scroll down a bit too far, then clicking the button (even the same buttons that previously worked) will result in the layout scrolling up to roughly half of the way up the listview instead of the top.
Here is the method that does the scrolling, it's rather simple:
public void backToTop(View view) {
lv = (ListView)findViewById(R.id.listview);
lv.smoothScrollToPosition(0);
}
This method is triggered when any of the buttons are clicked.
I have also tried to use the "scrollTo(0, 0)" function, but that failed to do anything.
Any help would be appreciated!
**edit: After testing some more, it appears as though the point where scrolling does not seem to function properly anymore is when the listview is no longer visible on the page. As soon as I scroll past it, the buttons begin to function incorrectly.
Edit 2: SOLVED. My solution: I changed the line
lv.smoothScrollToPosition(0);
to:
lv.setSelected(0);
This seems to give the correct behaviour for all my buttons at any position that the user has placed their screen. Using setSelected does not seem to have the side-effect that I was expecting of automatically triggering the click-event. Hooray!
My solution: I changed the second line of my backToTop method:
lv.smoothScrollToPosition(0);
to:
lv.setSelected(0);
This seems to give the correct behaviour for all my buttons at any position that the user has placed their screen. Using setSelected does not seem to have the side-effect that I was expecting of automatically triggering the click-event. Hooray!