Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

android - Lag in adding fragments to NestedScrollView

I have a NestedScrollView in which I have to add multiple fragments with having recycler views or view pagers. (I cannot use recycler view with Item View type due to a requirement)

Every fragment inside this NestedScrollView will take care of it's API call and view. Everything is working fine but when I am adding fragment more than 15, it starts lagging, and Lag is too much on old devices with fewer resources like RAM (Not so much old but they are pre lollipop)

How do I add my fragment on run time? below is the code

val fragmentTransAction = childFragmentManager.beginTransaction()
                                        fragmentTransAction.add(R.id.home, xFrag.create(homeSection), homeSection.id)
                                        fragmentTransAction.commit()

My XML file is below

<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:id="@+id/main_scroll"
        tools:context=".view.home.HomeMainFragment"
        android:layout_marginTop="@dimen/home_toolbar_height">

        <LinearLayout
            android:id="@+id/home_list_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" />
    </androidx.core.widget.NestedScrollView>

It's lagging too much when it's the first time creation of fragment, I have tried to add the first five fragments simply and others in Handler() but no luck.

What is the best way to achieve a smooth performance for adding the fragment in nested scroll view, I have tried to search a lot but unable to find anything which can be applied.

question from:https://stackoverflow.com/questions/65875107/lag-in-adding-fragments-to-nestedscrollview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...