1

This is my xml file

<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/nested_scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
    
                    <include layout="@layout/container_parent_child_graph" />
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#002649">
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#001525"
                        android:orientation="vertical">
    
                        <LinearLayout
                            android:id="@+id/ln_application_used"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:background="#001525"
                            android:gravity="center"
                            android:orientation="horizontal">
    
                            <include layout="@layout/view_list_tab_view_layout" />
    
                        </LinearLayout>
    
                        <LinearLayout
                            android:id="@+id/ln_container_all_apps_wise"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginStart="@dimen/dp_16"
                            android:layout_marginEnd="@dimen/dp_16"
                            android:background="@drawable/avatar_borders"
                            android:orientation="vertical"
                            android:visibility="gone">
    
                            <androidx.recyclerview.widget.RecyclerView
                                android:id="@+id/daily_monitor_list"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:nestedScrollingEnabled="false" />
    
                            <androidx.recyclerview.widget.RecyclerView
                                android:id="@+id/weekly_monitor_list"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_marginStart="@dimen/dp_8"
                                android:layout_marginEnd="@dimen/dp_8"
                                android:nestedScrollingEnabled="false" />
                        </LinearLayout>
    
                        <LinearLayout
                            android:id="@+id/ln_container_category_wise"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginStart="@dimen/dp_16"
                            android:layout_marginEnd="@dimen/dp_16"
                            android:background="@drawable/avatar_borders"
                            android:visibility="visible">
    
    
                            <androidx.recyclerview.widget.RecyclerView
                                android:id="@+id/categoryListRv"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toTopOf="parent"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent" />
                        </LinearLayout>
    
    
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </androidx.core.widget.NestedScrollView>

using this xml i want scroll vertically till view at top ln_application_used i.e view whose it is ln_application_used should visibile it should scroll before ln_application_used . i am trying using this code

nested_scroll_view.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->{
      nested_scroll_view.smoothScrollTo(ln_application_used)
}

fun NestedScrollView.smoothScrollTo(view: View) {
        var distance = view.top
        var viewParent = view.parent
        //traverses 10 times
        for (i in 0..9) {
            if ((viewParent as View) === this) break
            distance += (viewParent as View).top
            viewParent = viewParent.getParent()
        }
        smoothScrollTo(0, distance)
    }

but unable to scroll before ln_application_used it always scrolling full view please help me what i am doing wrong or how to achieve this .

MARSH
  • 117
  • 1
  • 7
  • 22
  • Confused whether you want to scroll horizontally or vertically? –  Dec 30 '21 at 04:25
  • @SagarBalyan Sorry my mistake i want vertically scroll – MARSH Dec 30 '21 at 04:30
  • Still dont understand the problem. Maybe you're not able to describe it properly. –  Dec 30 '21 at 04:33
  • @SagarBalyan I kept many view inside Nestedscrollview i am trying to scroll till specific view whose id is i.e when i scroll vertically once i will reach ln_application_used then i have to stop scrolling . please let me know if its not clear – MARSH Dec 30 '21 at 04:39
  • @SagarBalyan i hope you understand what i am trying to do ? – MARSH Dec 30 '21 at 04:56
  • Its clear now. So what is the problem that you're facing? –  Dec 30 '21 at 05:13
  • i tried using given code but its not stoping scrolling its scroll till bottom i want when i reach ln_application_used then i have to stop scrolling – MARSH Dec 30 '21 at 05:19
  • Read this: https://stackoverflow.com/questions/5763304/disable-scrollview-programmatically Maybe this could help –  Dec 30 '21 at 05:22
  • HI This does not help in my 1,2,3,4,5,6 view are there only 1 and 2 view are visible in screen now i want when i do scroll till 5 and it came on top then i have to stop scrolling – MARSH Dec 30 '21 at 11:51

0 Answers0