0

I have a recycler view and a banner AD in fragment view and i want to scroll ad with the recycler view when i scroll it down. i am using nested scroll for it and ad is scrolling fine initially. but when i scroll it down and more data comes from server then its not remain smooth and stopping some times. I have tried every sol on stack but nothing working for me.

Here is some code.

fragment_all.xml :

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:id="@+id/nestedScroll"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:scrollbars="none"
        >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:visibility="gone"
            android:focusableInTouchMode="true"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
        </com.google.android.gms.ads.AdView>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/news_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:nestedScrollingEnabled="false"
             />
    </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

fragment_all.java :

                          nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            if(v.getChildAt(v.getChildCount() - 1) != null) {
                if ((scrollY >= (v.getChildAt(v.getChildCount() - 1).getMeasuredHeight() - v.getMeasuredHeight())) &&
                        scrollY > oldScrollY) {

                    visibleItemCount = layoutManager.getChildCount();
                    totalItemCount = layoutManager.getItemCount();
                    pastVisibleItems = ((LinearLayoutManager) recyclerView.getLayoutManager())
                            .findFirstVisibleItemPosition();

                        if ((visibleItemCount + pastVisibleItems) >=totalItemCount) {

                            if (!loadingInside) {
                            loadingInside = true;
                            postNo = postNo + 15;
                            getDataFromUrl(postNo);
                        }
                        }
                }
                }
            }
           });

NOTE : i have tried solutions like :

<app:layout_behavior="@string/appbar_scrolling_view_behavior"
                      android:nestedScrollingEnabled="false"/>
plase
  • 361
  • 1
  • 3
  • 9
  • have a look here https://stackoverflow.com/questions/46638779/pagination-not-work-for-the-recyclerview-within-nestedscrollview/46638845#46638845 – AskNilesh Aug 03 '18 at 11:28
  • 1
    @NileshRathod i mentioned it in the note that i tried the solutions like that. – Droid Developer Aug 03 '18 at 11:29
  • Check :- https://stackoverflow.com/questions/37301724/recyclerview-inside-nested-scrollview-scroll-but-does-not-fast-scroll-like-norma & https://stackoverflow.com/a/33143512/3974530 – InsaneCat Aug 03 '18 at 12:01
  • In general, always avoid using `wrap_content` for a recyclerview. Using `wrap_content` removes all the performance benefits that recyclerview is trying to give you in the first place. If you want an adview at the top of your list, try creating a recyclerview that uses two different view types, and put the ad as the first item **inside** the recyclerview. – Ben P. Aug 03 '18 at 14:43

2 Answers2

0

Please set this

rec_view_notification.setLayoutManager(new LinearLayoutManager(getContext(), 
                  LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollHorizontally() {
                return false;
            }

            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
Ricky Patel
  • 439
  • 2
  • 12
0

You can set your RecyclerView Nested Scrolling false

Like

recyclerViewSignup.setNestedScrollingEnabled(false);
arlo shie
  • 134
  • 1
  • 8