android-layout-samples
android-layout-samples copied to clipboard
Potential Mistake ?
Hey lucas,
First off, thank you for this repo. this is an challenging, but worthwhile endeavor.
I was going through TweetElement.java
, when I caught something odd with getMeasuredHeightWithMargins(UIElement uiElement)
and getHeightWithMargins(UIElement)
. For ease, I have attached the methods below:
private int getHeightWithMargins(UIElement element) {
final MarginLayoutParams lp = (MarginLayoutParams) element.getLayoutParams();
return element.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
}
private int getMeasuredHeightWithMargins(UIElement element) {
final MarginLayoutParams lp = (MarginLayoutParams) element.getLayoutParams();
return element.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
}
As you can tell, there is no different between the two. I'm still learning, so I might be wrong, but do you mean to call element.getHeight()
in the first method? If so let me know, I'd be happy to submit a PR.
@yrizk
Please note the first method is called in onLayout ()
. At that time, the MeasuredHeight
of UIElement is determined, but not the actual Height.
I agree that the method is kind of duplicated.
Good points! In case you missed it, I recommend having a look at Litho. It incorporates a lot of these optimizations (and more!) behind a simple declarative API :-)