RelativeLayout does exactly what the documentation says it should be
doing. The size and position is are assigned in onLayout(). Here is
the code:

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        //  The layout has actually already been performed and the positions
        //  cached.  Apply the cached values to the children.
        int count = getChildCount();

        for (int i = 0; i < count; i++) {
            View child = getChildAt(i);
            if (child.getVisibility() != GONE) {
                RelativeLayout.LayoutParams st =
                        (RelativeLayout.LayoutParams) child.getLayoutParams();
                child.layout(st.mLeft, st.mTop, st.mRight, st.mBottom);

            }
        }
    }

It's just using cached values computed in onMeasure(), which does not
go against the concepts of ViewGroups as defined by the javadoc.

On Fri, Jun 12, 2009 at 10:00 AM, Matt<[email protected]> wrote:
>
> According to 
> http://developer.android.com/guide/topics/ui/custom-components.html:
>
> onMeasure(int, int)     Called to determine the size requirements for this
> view and all of its children.
> onLayout(boolean, int, int, int, int)   Called when this view should
> assign a size and position to all of its children.
>
> RelativeLayout doesn't do this; it actually assigns a size and
> position to all of its children in onMeasure.  From the source code of
> RelativeLayout:
>   �...@override
>    protected void onLayout(boolean changed, int l, int t, int r, int
> b) {
>        //  The layout has actually already been performed and the
> positions
>        //  cached.  Apply the cached values to the children.
>
> This is bad because, I wanted to override a RelativeLayout and assign
> it a specific height.  However, the children of this RelativeLayout
> would not respect the height I assigned, because the children assign
> themselves positions and sizes in onMeasure.  And therefore the
> children don't fit in the RelativeLayout.
>
> IMHO it's a bad sign of the design when the actual framework doesn't
> follow its own design.  I know this sounds like a flame or a rant, but
> I'm just trying to point out what I believe to be a underlying problem
> here.  If you can't override a RelativeLayout then it should have been
> declared final (but that's too drastic).  Perhaps the onMeasure and
> onLayout need to be rethought (guess it's too late for that :).  At
> the very least, the documentation should be updated so that one knows
> that when subclassing RelativeLayout, that the size and position of
> all of its children are actually assigned in onMeasure and onLayout.
>
>
> >
>



-- 
Romain Guy
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to