0

I have scrollview inside Recycler view. I am trying to achieve swipeable behaviour like inshorts but the card should scroll to the bottom so user can see all the contents. Once scrollview bottom has been reached then swipe should work to move to next article.

I have implement swipeable behaviour using stacklayoutmanager. The problem is I am not able to scroll to the bottom.

Below is implementation

Recycler view inside main activity

    <androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

MainActivity code, added PagerSnapHelper for fling effect.

        adapter = new RecyclerViewAdapter(setData(),this);
     layoutManager = new CustomLayoutManager(StackLayoutManager.ScrollOrientation.BOTTOM_TO_TOP,1, this);
    layoutManager.setPagerFlingVelocity(600);
    recyclerView.setLayoutManager(layoutManager);
           LinearSnapHelper snapHelper = new CustomSnapHelper();
    snapHelper.attachToRecyclerView(recyclerView);
    recyclerView.setAdapter(adapter);

CustomLayoutManager class which extends the library for swipeable behaviour

class CustomLayoutManager(orientation: ScrollOrientation, count:Int, context: Context) : StackLayoutManager(orientation, count, context){

private var isScrollEnabled = true

fun setScrollEnabled(flag: Boolean) {
    isScrollEnabled = flag
}

override fun canScrollVertically(): Boolean {
    //Similarly you can customize "canScrollHorizontally()" for managing horizontal scroll
    return isScrollEnabled && super.canScrollVertically()
}

}

item view inflated in adapter class

 <ScrollView
            android:id="@+id/scroll"
            android:scrollbars="none"
            android:nestedScrollingEnabled="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="15dp"
                android:layout_marginEnd="15dp"
                android:text="very very long text will add here"
                android:textSize="16sp" />

        </ScrollView>

Here in the below image, when trying to scroll to the bottom to read the complete content but recyclerview swipe behaviour becomes active and next item becomes visible.

Update I have replaced scrollview with nestedscrolledview and found out that scrollVerticallyBy() method present in RecyclerView.LayoutManager() does not invoke, only scrollHorizontallyBy() is getting called n times.

I have tried so far but not working

ScrollView inside RecyclerView won't scroll

https://stackoverflow.com/a/41139693/7368819

https://stackoverflow.com/a/34060065/7368819

https://stackoverflow.com/a/10334353/7368819

enter image description here

Aayush Singh
  • 288
  • 2
  • 14
  • have you tried with nestedscrollview? – Pawel Apr 06 '22 at 16:02
  • @Pawel No, how can nestedscrollview make any difference? – Aayush Singh Apr 06 '22 at 16:09
  • Have you tried `NestedScrollView`? – Ticherhaz FreePalestine Apr 06 '22 at 16:32
  • yes, i did just now and added nestedscrolling enabled = true but didnot work either – Aayush Singh Apr 06 '22 at 16:33
  • Both recyclerview and scrollview are tracking touch-drag to intercept it and begin their scrolling touch event. Since recyclerview is higher in view hierarchy it will always be the first one to execute its intercept. NestedScrollView is different because it starts nested scrolling event which is more sophisticated and lets nested scrolling children interact with nested scrolling parents during the scroll. If it doesn't work just by plugging it in you'd need to extend recyclerview and add nested scrolling parent behavior which is a bit tedious but the cleanest way to achieve what you need. – Pawel Apr 06 '22 at 16:38
  • can you please provide any good resource to achieve it – Aayush Singh Apr 06 '22 at 16:49
  • @TicherhazFreePalestine I have replaced scrollview with nestedscrolledview and found out that scrollVerticallyBy() method present in RecyclerView.LayoutManager() does not invoke, only scrollHorizontallyBy() is getting called n times. – Aayush Singh Apr 08 '22 at 07:12
  • Only a `ViewPager2` with attribute `android:nestedScrollingEnabled="true"` is enough to make an Inshorts like card mechanism. And to make child content scrolling, you can use a Scrollview inside the child row. – Lalit Fauzdar Apr 08 '22 at 07:28
  • @LalitFauzdar, thanks for you answer, i am able to scroll the child content but once i reach the bottom of the scrollview present inside the child row, next article swipe is not working. – Aayush Singh Apr 08 '22 at 08:45
  • i think you should disable the touch of recycler view when scrollview is being touched. – UD.. Apr 17 '22 at 04:44
  • @UD..yeah man!! i have implemented this. Actually i was looking for a clean soltuion. – Aayush Singh Apr 17 '22 at 04:49

0 Answers0