Skip to content

Instantly share code, notes, and snippets.

@seanabraham
Created October 30, 2015 20:19
Show Gist options
  • Save seanabraham/151cd057ec4ba3216adc to your computer and use it in GitHub Desktop.
Save seanabraham/151cd057ec4ba3216adc to your computer and use it in GitHub Desktop.
LoggingRecyclerView and LoggingLinearLayoutManager which helps debugging RV issues.
public class LoggingLinearLayoutManager extends LinearLayoutManager {
public LoggingLinearLayoutManager(Context context) {
super(context);
}
public LoggingLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public LoggingLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
Log.d("SEAN", "onLayoutChildren State: " + state);
super.onLayoutChildren(recycler, state);
}
}
public class LoggingRecyclerView extends RecyclerView {
public LoggingRecyclerView(Context context) {
super(context);
}
public LoggingRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public LoggingRecyclerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
logChildren();
super.onLayout(changed, l, t, r, b);
logChildren();
}
private void logChildren() {
for (int i = 0, size = getChildCount(); i < size; i++) {
View child = getChildAt(0);
Log.d("SEAN", getChildViewHolder(child) + "--> " + getLtrb(child));
}
}
private String getLtrb(View view) {
return "l: " + view.getLeft() + " r: " + view.getRight() + " t: " + view.getTop() + " b: " + view.getBottom();
}
@Override
public ViewHolder getChildViewHolder(View child) {
ViewHolder holder = super.getChildViewHolder(child);
Log.d("SEAN", "getChildViewHolder(child): " + holder);
return holder;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment