Created
October 30, 2015 20:19
-
-
Save seanabraham/151cd057ec4ba3216adc to your computer and use it in GitHub Desktop.
LoggingRecyclerView and LoggingLinearLayoutManager which helps debugging RV issues.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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