Home > Enterprise >  RecyclerView nested in LinearLayout as well as Scrollview not scrolling to specific recycler item po
RecyclerView nested in LinearLayout as well as Scrollview not scrolling to specific recycler item po

Time:06-13

My code below doesnt work for each specific scrollto or smoothScrollTo, can anyone help me? I basically want to be able to dynamically scroll to a specific Item position in the activity, e.g. if a specific recyclerviewItem has been clicked on it will go to the activity and scroll to the specific item. The position variable has been ranging from "recyclerview.getChildAdapterPosition(itemview)" to itemview.Bottom which also doesn't work. Help would be appreciated.

     private fun focusOnView(scroll: ScrollView, itemView : View?,position :Int) {
        scroll.post(Runnable {
            if (editBox != null) {
                val x= 1

                // scroll.scrollTo(0,NestedScrollView.FOCUS_DOWN)
              //  scroll.smoothScrollTo(0, scroll.bottom)
                scroll.smoothScrollTo(0,position)
                //scroll.fullScroll(130)
            }
        })
    }



  <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@ id/scrollView"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@ id/contentreyclerpager"
                android:layout_width="match_parent"
                android:paddingTop="10dp"
                android:layout_height="wrap_content" />


        </RelativeLayout>


    </ScrollView>

CodePudding user response:

Why you use the nestedScollView smoothScrollTo with the position you have to give x,y coordonate i think in your case you can use recycleView.smoothScrollToPosition(yourPosition);

  • Related