回收器查看滚动缓慢且卡住的安卓



我在回收视图的row_item中使用MathView。当我滚动我的回收器查看它的滚动卡住了。是否有可能因为MathView而卡住我的回收器视图的原因?

在我的代码中,Type = 3是Mathview数据

if (queList[position].type == 1 || queList[position].type == 2) {
holder.txtQue!!.setText(Html.fromHtml(Html.fromHtml(queList[position].question).toString()))
holder.math_txtQue?.visibility = View.GONE
if (isQuestionAnswer(queList[position].is_correct, 1)) {
holder.txtAnswer!!.setText(Html.fromHtml(Html.fromHtml(queList[position].opt_1).toString()))
holder.math_txtAnswer?.visibility = View.GONE
}
if (isQuestionAnswer(queList[position].is_correct, 2)) {
holder.txtAnswer!!.setText(Html.fromHtml(Html.fromHtml(queList[position].opt_2).toString()))
holder.math_txtAnswer?.visibility = View.GONE
}
} else if (queList[position].type == 3) {
holder.txtQue?.visibility = View.GONE
holder.math_txtQue?.visibility = View.VISIBLE
holder.math_txtQue?.text = Html.fromHtml(queList[position].question).toString()
holder.mathDesc?.text = Html.fromHtml(queList[position].description).toString()
if (isQuestionAnswer(queList[position].is_correct, 1)) {
holder.txtAnswer?.visibility = View.GONE
/*holder.math_txtAnswer?.visibility = View.VISIBLE
holder.math_txtAnswer?.text = Html.fromHtml(queList[position].opt_1).toString()*/
}
if (isQuestionAnswer(queList[position].is_correct, 2)) {
holder.txtAnswer?.visibility = View.GONE
holder.math_txtAnswer?.visibility = View.VISIBLE
holder.math_txtAnswer?.text = Html.fromHtml(queList[position].opt_2).toString()
}
}

我的布局文件 :-

<android.support.v7.widget.RecyclerView
android:id="@+id/questionReadList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar_top"
android:background="@color/colorPrimary"
android:divider="@null"
android:nestedScrollingEnabled="false"
android:dividerHeight="0dp"></android.support.v7.widget.RecyclerView>

此问题和解决方案分别有多种原因。

  1. 如果您在NestedScrollView中使用RecyclerView.

    在您的情况下为假

  2. 您发布的代码在膨胀视图(即onBindViewHolder()方法(后已经做了太多复杂或合乎逻辑的工作。

    为此
    ,您首先尝试评论所有逻辑,只需尝试仅夸大View

您可以在JSON解析时执行所有逻辑操作。 使用getItemViewType()&viewType实现根据您的 quesType 膨胀View

愿这对你有所帮助

最新更新