I want to keep scrollview scroll position of a fragment. This fragment (HomeFragment.kt
) is one of several fragments within a fragment with bottom navigation (DashboardFragment.kt
).
This is how HomeFragment.kt
loaded (This is a snippet of DashboardFragment.kt
)
private fun loadHomeFragment() {
homeFragment = HomeFragment()
dashboardFragmentManager.beginTransaction()
.setCustomAnimations(
android.R.animator.fade_in,
android.R.animator.fade_out
)
.replace(R.id.content, homeFragment, "1")
.commit()
}
And this is the scrollview layout (This is a snippet of HomeFragment.kt
layout) :
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/swipeBaseLayout">
<ScrollView
android:id="@+id/baseLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="32dp">
<com.synnapps.carouselview.CarouselView
android:id="@+id/carouselView"
android:layout_width="match_parent"
android:layout_height="300dp"
app:fillColor="#FFFFFFFF"
app:pageColor="#00000000"
app:pageTransformInterval="800"
app:radius="3dp"
app:slideInterval="5000"
app:strokeColor="#FFFFFFFF"
app:strokeWidth="1px" />
<RelativeLayout>
.....
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
As you can see, I already have an id for the scrollview. But every time this fragment loaded or navigated back from another fragment (From another fragment to DashboardFragment.kt) (I'm using navigation component), it'll start from the top.
Is there any way to keep scrollview even after the fragment transaction? If there's any detail I missed to point out, just let me know.