Android快速碎片更换导致延迟
我目前正在开发一个类似测验的应用程序 在这个应用程序中,我有一个名为QuizaActivity的活动 在QuizaActivity中,我希望依次显示问题,并允许用户在它们之间导航。 因此,我考虑构建一个问题片段。 在布局中,我插入了显示问题的组件(CardView、EditText和一个ImageView)。 在代码中,我在创建视图时将数据加载到视图中 当用户尝试快速切换片段时,问题就会出现,输入开始变慢,所有内容都开始滞后。 这是我的密码: 片段布局Android快速碎片更换导致延迟,android,android-fragments,Android,Android Fragments,我目前正在开发一个类似测验的应用程序 在这个应用程序中,我有一个名为QuizaActivity的活动 在QuizaActivity中,我希望依次显示问题,并允许用户在它们之间导航。 因此,我考虑构建一个问题片段。 在布局中,我插入了显示问题的组件(CardView、EditText和一个ImageView)。 在代码中,我在创建视图时将数据加载到视图中 当用户尝试快速切换片段时,问题就会出现,输入开始变慢,所有内容都开始滞后。 这是我的密码: 片段布局 <android.support.v
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/question_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="centerCrop" />
<AutoCompleteTextView
android:id="@+id/AutoreTxtView"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="16dp"
android:fontFamily="sans-serif"
android:hint="Autore"
android:paddingLeft="15dp"
android:paddingRight="15dp" />
<AutoCompleteTextView
android:id="@+id/OperaTxtView"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="16dp"
android:fontFamily="sans-serif"
android:hint="Opera"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:singleLine="true" />
<AutoCompleteTextView
android:id="@+id/LuogoTxtView"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="16dp"
android:fontFamily="sans-serif"
android:hint="Luogo"
android:paddingLeft="15dp"
android:paddingRight="15dp" />
<AutoCompleteTextView
android:id="@+id/AnnoTxtView"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="16dp"
android:fontFamily="sans-serif"
android:hint="Anno"
android:paddingLeft="15dp"
android:paddingRight="15dp" />
<AutoCompleteTextView
android:id="@+id/MovimentoTxtView"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="16dp"
android:hint="Movimento"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_marginBottom="8dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
下一个片段代码
mFragmentManger.beginTransaction()
.replace(R.id.FragContainer, listaIstanzeQuestion.get(question_index))
.addToBackStack("key_" + question_index)
.commit();
返回上一个片段的简单PopBackStack()
mFragmentManger.popBackStack();
有没有更有效的方法来获得我想要的结果?
我已经尝试清理代码并减少布局组件。如果我删除一些布局组件,性能会提高,但我需要它们
谢谢。如果您评论ImageView部分,性能如何?我的意思是将位图设置为相同的,无论如何,我忘了提到,在允许用户在它们之间导航之前,我创建了所有的距离,并将它们存储在一个数组中(ListaInstanceQuestion)
mFragmentManger.popBackStack();