Recyclerview滚动缓慢并卡死了Android

时间:2018-09-10 11:17:11

标签: android android-recyclerview kotlin

我在recyclerview的row_item中使用MathView。当我滚动我的Recyclerview时,其滚动卡住了。可能是因为MathView卡住了我的recyclerView吗?

在我的代码中,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 个答案:

答案 0 :(得分:0)

这个问题的原因和解决方法各有不同。

  1. 如果您在RecyclerView中使用NestedScrollView

      

    在您的情况下为假

  2. 您发布的代码在夸大View后,即在onBindViewHolder()方法中已经进行了太多复杂或逻辑工作。

      

    为此
      您首先尝试注释所有逻辑,仅尝试仅填充View

您可以在JSON解析时执行所有逻辑运算。使用ViewgetItemViewType()实现,根据您的quesType膨胀viewType

这可以帮助您