android-layout-samples icon indicating copy to clipboard operation
android-layout-samples copied to clipboard

Potential Mistake ?

Open yrizk opened this issue 9 years ago • 2 comments

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 avatar Jun 13 '15 19:06 yrizk

@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.

rayworks avatar Aug 02 '17 03:08 rayworks

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 :-)

lucasr avatar Aug 02 '17 09:08 lucasr