question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`RecycleView` with `viewclass` using dynamic `height` is not smooth

See original GitHub issue

Versions

  • Python: 3.7.4
  • OS: Arch Linux
  • Kivy: v2.0.0.dev0, git-7947abf, 20191025
  • Kivy installation method: pip install --user git+https://github.com/kivy/kivy.git

Description`

When using RecycleView with a viewclass using dynamic height, the scrolling is “jumping”, it’s not smooth at all. Each time a new item appears on screen, there is a little “jump” (the scroll bar is going in the opposite direction then the right size is set), which is really bad when scrolling many items at once. Once the entire list of data has been scrolled once, the next time we scroll it is smooth as expected.

This bug is related to https://github.com/kivy/kivy/issues/6580 but it’s a different issue.

Code and Logs

from kivy.app import App
from kivy.lang import Builder

KV = '''
<CustomView@BoxLayout>:
    size_hint: 1, None
    text: ''
    Label:
        id: test_label
        size_hint: 1, None
        on_size: root.height = self.height
        text_size: root.width, None
        size: self.texture_size
        text: root.text


RecycleView:
    viewclass: 'CustomView'
    data: [{"text": f"{i} {'test'*i}"} for i in range(300)]
    scroll_y: 0
    RecycleBoxLayout:
        id: layout
        default_size: None, None
        default_size_hint: 1, None
        size_hint_y: None
        height: self.minimum_height
        orientation: 'vertical'
'''

class TestApp(App):
    def build(self):
        return Builder.load_string(KV)

if __name__ == '__main__':
    TestApp().run()

This script is displaying a 300 BoxLayout containing a Label were text is growing on purpose (to augment the height of each item). expected result: when you scroll the RecycleView, the scrolling should me smooth, quick, and nice looking actual result: there are jumps on each items. If you scroll slowly, you can notice clearly that the jump happen when a new item appears in the view. If you scroll quickly, there are many jumps and the scrolling is not smooth at all. Once the entire list has been scrolled once, everything is smooth as expected.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
tshirtmancommented, Mar 25, 2021

if you can pre-compute a sufficiently good approximation of the size of the item before displaying it, and put that value in the key_size key of your dict (that you can then update when the actual size is computed), then you can significantly improve the experience.

1reaction
mathamcommented, Apr 22, 2021

If the size is dynamic, it gets the sizes whenever the size of any widget changes and does a re-layout. This is costly and can lead to jumps in scrollview if the new size is very different than the original size.

As @tshirtman said, you can improve the performance if you can initially estimate the size of the dynamic widgets, because that leads to less jumping. Similarly, if you can save the last known widget size in the data dict, that size will be used initially when re-showing a previously shown widget. This will save the cost of laying it out again, as in the example he posted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RecyclerView scroll up is not smooth when the height isn't fixed
It works fine if you scroll down the list, but when you scroll back up: As the previous ViewHolder is drawn it's height...
Read more >
Using the RecyclerView | CodePath Android Cliffnotes
The RecyclerView is a ViewGroup that renders any adapter-based view in a similar way. It is supposed to be the successor of ListView...
Read more >
Create dynamic lists with RecyclerView - Android Developers
Several classes work together to build your dynamic list. RecyclerView is the ViewGroup that contains the views corresponding to your data. It' ...
Read more >
Everything You Should Know To Create A Recyclerview
We need to use this method to sort our “data” list. We will call this method in OnCreateViewHolder() class before creating the view....
Read more >
RecyclerView cannot size itself based on the measured ...
Example: Horizontally scrolling RecyclerView with width=match_parent and height=wrap_contents and properly measured child views does not display ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found