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 .