Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

Nested scrolling #14

Open
laszlomagyar opened this issue Jan 18, 2018 · 7 comments
Open

Nested scrolling #14

laszlomagyar opened this issue Jan 18, 2018 · 7 comments

Comments

@laszlomagyar
Copy link

laszlomagyar commented Jan 18, 2018

Nested scrolling with my (and neither with your) code does not working at all. It just makes my screen unscrollable.

If i change the SpannedGridLayoutManager to a simple LinearLayoutManager, the NestedScrolling works fine, so the problem is in the LayoutManager.

Please fix it.
Thank you.

@fazal88
Copy link

fazal88 commented Jun 25, 2018

dealing with same issue. please help i using this layoutmanager in nestedscrollview

@jmartinesp
Copy link
Owner

I'm sorry for the very late reply, I haven't had much time to work on my libraries and this one always takes lots of time to fix. Could you provide an example of what you are trying to do?

@mrsylerpowers
Copy link

mrsylerpowers commented Oct 28, 2018

@Arasthel Trying to have a nestedscrollview as a parent. While having SpannedGridLayoutManager as one of its children but when adding a your library it doesn't allow nested scrolling and is unscrollable.

@DennyWeinberg
Copy link

@mrsylerpowers
Should be resolved by #38.

@mrsylerpowers
Copy link

mrsylerpowers commented Dec 11, 2018

@DennyWeinberg Edit: @Arasthel
I am able to get the nested scrolling working but in order to do that I for some reason have to set the recycler views height in order to see anything when a NestedScrollView is the parent of the recyclerview.

My whole setup is:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<LinearLayout
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

       // Things I want  to appear on top of the Recycler View

        </LinearLayout>
    <android.support.v7.widget.RecyclerView  // Recycler View For the feed I have
        android:id="@+id/feed"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:nestedScrollingEnabled="false"
        android:padding="2dp"
        />
</LinearLayout>

</android.support.v4.widget.NestedScrollView>

And here are the Item views that I am using and inflating inside of my recyclerAdapter :

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<android.support.constraint.ConstraintLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" >
<.SquareImageView
    android:layout_width="match_parent"
    android:id="@+id/content_box"
    android:layout_height="wrap_content"
    android:layout_margin="2dp"
    android:src="@drawable/ic_image_black_24dp"
>

    </.SquareImageView>
</android.support.constraint.ConstraintLayout> 

and my adapter:

        RecyclerView mRecyclerView = view.findViewById(R.id.feed);
        FeedViewExpanderAdapter mAdapter = new FeedViewExpanderAdapter();

        GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),4,LinearLayoutManager.VERTICAL,false);
        SpannedGridLayoutManager uLayoutManager = new SpannedGridLayoutManager(SpannedGridLayoutManager.Orientation.VERTICAL, 4);
        uLayoutManager.setSpanSizeLookup(new SpannedGridLayoutManager.SpanSizeLookup(position -> {
                    if(mAdapter.postViews.get(position).getExpandType() == FeedViewExpanderAdapter.EXPANDED_ITEM){
                        return new SpanSize(3,3);
                    }
                    else {
                        return new SpanSize(1,1);
                    }
                }));


        mRecyclerView.setLayoutManager(uLayoutManager);
        mRecyclerView.setAdapter(mAdapter);

When I use the SpannedGridLayoutManager the recycler view is never visible when rendered in my app but when I switch to the GridLayoutManager I am able to see it . This only happens when I put it as a child as a NestedScrollView.

@rafalzawadzki
Copy link

rafalzawadzki commented Dec 22, 2018

I am having exactly the same problem.

I would like to set the height of the RecyclerView to wrap_content (as in the example above) but then it does not get rendered. I suspect the height is 0 and this might be related to auto-measure feature - or the lack of it - of SpannedGridLayoutManager. I got the idea from this answer on SO.

// edit
According to this, I have overridden the isAutoMeasureEnabled method to return true and now the grid is shown. Additionally, setMeasuredDimension needs to be overridden to adjust the view height.

Adding this snippet in SpannedGridLayoutManager makes it almost work:

override fun isAutoMeasureEnabled() = true

override fun setMeasuredDimension(childrenBounds: Rect?, wSpec: Int, hSpec: Int) {
    setMeasuredDimension(width, rectsHelper.end)
}

The RecyclerView height is still not correct (a bit too much in my case), until now I did not find in the LayoutManager the right calculated height to use there.

@mrsylerpowers
Copy link

@rafalzawadzki It seems this a issue with just the rectsHelper.end calculator as mentioned in #43 even in original code there is extra space.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants