Last active
May 2, 2020 06:21
-
-
Save lucasr/391fbcb04479ebbe838c to your computer and use it in GitHub Desktop.
List layout built with the new TwoWayView API
This file contains hidden or 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 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