Android ui lag when scrolling multiple recyclerviews

My question is pretty simple, why is it lagging behind?

This layout:

    <ScrollView>
         <RelativeLayout>
             <RecyclerView1/>
             <RecyclerView2/>
             <RecyclerView3/>
         </RelativeLayout>
    </ScrollView>

      

recyclerview are (1,2) horizontal and (3) vertical with height as wrap_content. When I go back to rv (3) it keeps up, only when showing rv (1,2)

There is enough reason why this lag when they are filled with children and not when empty? It doesn't make any sense to me.

I believe there is a lot I don't know in the background. Measures or something else? Does anyone know what's going on? Or if someone can just point me in the right direction to beat this issue. Is there something I am doing not recommended?

To clean things up, I included my ViewHolder and adapter for RV:

ViewHolder

public class ObjHolder extends RecyclerView.ViewHolder {

 private static String              TAG         = "[ObjHolder]";

 public Obj                         mObj;
 public CardView                    mContainer;
 public TextView                    mAttr1;
 public TextView                    mAttr2;
 public TextView                    mAttr3;
 public TextView                    mAttr4;
 public TextView                    mAttr5;

 public OnObjClickListener  mCallback   = null;

 public ObjHolder(View v) {
    super(v);

    mContainer = (CardView) v;

    mAttr1 = (TextView) mContainer.findViewById(R.id.obj_details_attr1);
    mAttr2 = (TextView) mContainer.findViewById(R.id.obj_details_attr2);
    mAttr3 = (TextView) mContainer.findViewById(R.id.obj_details_attr3);
    mAttr4 = (TextView) mContainer.findViewById(R.id.obj_details_attr4);
    mAttr5 = (TextView) mContainer.findViewById(R.id.obj_details_attr5);

    mContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (DEBUG) Log.d(TAG, "onClick()");
            if (mCallback != null) mCallback.onObjClick(mObj);
        }
    });
 }

 public void setOnObjClickListener(OnObjClickListener onObjClickListener) {
    mCallback = onObjClickListener;
 }
}

      

Adapter

public class ObjAdapter extends AbstractCursorRecyclerViewAdapter<RecyclerView.ViewHolder> implements OnObjClickListener {

 private static final String    TAG     = "[ObjAdapter]";

 private OnObjClickListener mCallback   = null;

 public ObjAdapter( Context context, Cursor cursor) {
    super(context, cursor);
 }

 @Override
 public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, Cursor cursor) {

    if (viewHolder instanceof ObjHolder) {

        ObjHolder objHolder = (ObjHolder) viewHolder;

        final Obj obj = new Obj(cursor);

        objHolder.mAttr1.setText(obj.attr1);
        objHolder.mAttr2.setText(obj.attr2);
        objHolder.mAttr3.setText(obj.attr3);
        objHolder.mAttr4.setText(obj.attr4);
        objHolder.mAttr5.setText(obj.attr5);
        objHolder.mObj = obj;

        objHolder.setOnObjClickListener(this);

        MyDatabase db = MyDatabase.getInstance(getContext());
        Cursor childCursor = db.getChildren(obj);

        // Count children who matters to present in the card
        int attribMatch = 0;
        try {
            while (childCursor.moveToNext()) {
                if (childCursor.getString(1) != null) {
                    int newStatusValue = Integer.parseInt(childCursor.getString(1));

                    if (newStatusValue >= 5) attribMatch++;
                }
            }
        }
        finally {
            childCursor.close();
        }

        if (Integer.parseInt(obj.statusValue) >= 10) objHolder.mContainer.setForeground(ContextCompat.getDrawable(getContext(), R.drawable.bg_warning_border));

        objHolder.mAttrib1.setText(""
                                    + attribMatch);

        if (attribMatch > 0) objHolder.mAttrib2.setTextColor(getContext().getResources().getColor(R.color.red));

    }
 }

 @Override
 public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,
                                        int viewType) {
    return new ObjHolder(
                LayoutInflater.from(parent.getContext()).inflate(R.layout.obj_details, parent, false));
 }

 public void setOnObjClickListener(OnObjClickListener onObjClickListener) {
    mCallback = onObjClickListener;
 }

 @Override
 public void onObjClick(Obj obj) {
    if (mCallback != null) mCallback.onObjClick(obj);
 }
}

      

+3


source to share


2 answers


You added this to AndroidManifest.xml. if not, you can try this. it solves my problem.



android:hardwareAccelerated="true" 

      

0


source


Don't use the recycler view in another recycler view as the parent view tries to paint the entire child view, resulting in delays. Try to make one viewer with different types of views.



0


source







All Articles