Giter VIP home page Giter VIP logo

Comments (10)

rubensousa avatar rubensousa commented on May 29, 2024

I don't understand the question, sorry.
What are you trying to achieve? You want the sample to contain lots of nested recyclerviews?

from gravitysnaphelper.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on May 29, 2024

Which part exactly isn't understood?

I didn't ask about nested RecyclerViews, though this can be a case of heavy pages.

from gravitysnaphelper.

rubensousa avatar rubensousa commented on May 29, 2024

I meant the title: "How to choose if it should create the views around?"

This sample has 4 nested RecyclerViews. Each one has a different SnapHelper. You mentioned the onBindViewHolder just gets called once in this case, which is ok, although it doesn't reflect the case in real life apps. So, what's the problem here?

EDIT:
Maybe this is useful: https://medium.com/google-developers/recyclerview-prefetch-c2f269075710

from gravitysnaphelper.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on May 29, 2024

onBindViewHolder Should be called not just for the current one, but also for those near it.
That's why I mentioned RecyclerView and ViewPager.
If you use this library to be used on the case of a full screen cell, for some reason, it doesn't load those near it.
This was written some time ago, so maybe I was mistakenly writing this on the wrong repo.

from gravitysnaphelper.

rubensousa avatar rubensousa commented on May 29, 2024

Closing due to inactivity. This is question was out of scope for this library.

from gravitysnaphelper.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on May 29, 2024

@rubensousa I don't remember what it was about, but reading what I wrote, I think it was about the case that each cell would take whole screen (or just the whole width for horizontal scrolling), like a ViewPager, and that the issue is that it doesn't work like ViewPager.
This means that there is an issue, that the views around don't get updated till you actually see a part of them.
This is bad, because in the case of loading the images from the Internet for the cells, you will always first see a placeholder because it takes time to load each.
It's also bad because the creation of the near cells should be performed now, and not later.

from gravitysnaphelper.

rubensousa avatar rubensousa commented on May 29, 2024

Yes, I finally understood what you meant, since I faced this exact issue a few months ago. My fix was extending LinearLayoutManager and just return more extra space in getExtraLayoutSpace: https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager.html#getExtraLayoutSpace(android.support.v7.widget.RecyclerView.State). I think we need to use this as an alternative to ViewPager's setOffscreenPageLimit: https://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit(int)

This also happens in the original LinearSnapHelper and that's why I decided to close this, since the fix involves configuring the RecyclerView and its LayoutManager

from gravitysnaphelper.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on May 29, 2024

Can you please show how to do it?
How to force that at least one item from each side of the current one would be loaded?

from gravitysnaphelper.

rubensousa avatar rubensousa commented on May 29, 2024

I'm not sure if it's the best solution, but this was my workaround:

public class ViewPagerLinearLayoutManager extends LinearLayoutManager {

    private int offScreenPageLimit = 1;

    public ViewPagerLinearLayoutManager(Context context) {
        super(context);
    }

    public ViewPagerLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
        super(context, orientation, reverseLayout);
    }

    public void setOffscreenPageLimit(int extraPages) {
        this.offScreenPageLimit = extraPages;
    }

    @Override
    protected int getExtraLayoutSpace(RecyclerView.State state) {
        return super.getExtraLayoutSpace(state) * offScreenPageLimit;
    }
}

If you come up with another solution, please let me know :)

from gravitysnaphelper.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on May 29, 2024

I see. Thank you.

from gravitysnaphelper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.