Skip to content

Instantly share code, notes, and snippets.

@lucasr
Last active May 2, 2020 06:21
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lucasr/391fbcb04479ebbe838c to your computer and use it in GitHub Desktop.
Save lucasr/391fbcb04479ebbe838c to your computer and use it in GitHub Desktop.
List layout built with the new TwoWayView API
public class SimpleListLayout extends TwoWayLayoutManager {
public SimpleListLayout(Context context, Orientation orientation) {
super(context, orientation);
}
@Override
protected void measureChild(View child, Direction direction) {
measureChildWithMargins(child, 0, 0);
}
@Override
protected void layoutChild(View child, Direction direction) {
final int width = getDecoratedMeasuredWidth(child);
final int height = getDecoratedMeasuredHeight(child);
final int l, t, r, b;
if (getOrientation() == Orientation.VERTICAL) {
l = getPaddingLeft();
t = direction == Direction.END ? getLayoutEnd() : getLayoutStart() - height;
} else {
l = direction == Direction.END ? getLayoutEnd() : getLayoutStart() - width;
t = getPaddingTop();
}
r = l + width;
b = t + height;
layoutDecorated(child, l, t, r, b);
}
@Override
protected boolean canAddMoreViews(Direction direction, int limit) {
if (direction == Direction.END) {
return getLayoutEnd() < getEndWithPadding();
} else {
return getLayoutStart() > getStartWithPadding();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment