My question is quite simple, why does it lag?
This layout:
<ScrollView>
<RelativeLayout>
<RecyclerView1/>
<RecyclerView2/>
<RecyclerView3/>
</RelativeLayout>
</ScrollView>
recyclerview(1,2) are horizontal and (3) is vertical with height as wrap_content. When I get down to rv(3) it doesn't lag, only when showing rv(1,2)
Enough with the basics, why does this lag when they are filled with children and not when empty? It doesnt make any sence to me.
I believe there's alot going on in the background that I'm not aware about. Measures or something? Anyone know what's going on? Or if someone could just point me in the right direction to conquer this problem. Something I do that is discouraged?
To clearify things I include my ViewHolder and Adapter for the RV's:
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);
}
}