All you have to do is call measure() on the children yourself. Or you could
just use layout params :)
On Mar 3, 2013 12:04 PM, "Michael Dunn" <[email protected]> wrote:
> Thanks Mr. Guy. What would be the minimum required to use a value instead
> of LayoutParams (on the entire tree)? I don't believe this works:
>
> @Override
> protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
> setMeasuredDimension(mWidth, mHeight);
> }
>
>
> On Sun, Mar 3, 2013 at 11:52 AM, Romain Guy <[email protected]> wrote:
>
>> You call measureChildren() which in turns call measureChild() which looks
>> at the LayoutParams of each child.
>> On Mar 1, 2013 10:12 PM, "momo" <[email protected]> wrote:
>>
>>> I have a custom ViewGroup that's only ever managing the size and
>>> position of one child. I've override onMeasure and onLayout so that
>>> LayoutParams are never examined, yet it fails unless I do provide
>>> LayoutParams. Here are abbreviated summaries of the relevant portions of
>>> the class:
>>>
>>>
>>> public class SomeSpecialLayoutManager extends ViewGroup {
>>>
>>> @Override
>>> protected void onMeasure(int widthMeasureSpec, int
>>> heightMeasureSpec) {
>>> measureChildren(widthMeasureSpec, heightMeasureSpec);
>>> int w = mChild.getMeasuredWidth();
>>> int h = mChild.getMeasuredHeight();
>>> w = Math.max(w, getSuggestedMinimumWidth());
>>> h = Math.max(h, getSuggestedMinimumHeight());
>>> w = resolveSize(w, widthMeasureSpec);
>>> h = resolveSize(h, heightMeasureSpec);
>>> setMeasuredDimension(w, h);
>>> }
>>>
>>> @Override
>>> protected void onLayout(boolean changed, int l, int t, int r, int b)
>>> {
>>> mChild.layout( 0, 0, mWidth, mHeight );
>>> }
>>> }
>>>
>>>
>>> Using the above, the following *does* work:
>>>
>>> LayoutParams lp = mChild.getLayoutParams();
>>> lp.width = mWidth;
>>> lp.height = mHeight;
>>> mChild.setLayoutParams( lp );
>>>
>>> But since neither `onMeasure` nor `onLayout` even makes reference to
>>> `LayoutParams`, I wonder why it's required, or even how it's referenced at
>>> all. I would assume that since the layout pass grabs `mWidth` and
>>> `mHeight` directly, there'd be no need for the `LayoutParams` at all - and
>>> that a call to requestLayout would update it appropriately.
>>>
>>> However, when I isolate the above in a small program outside of a
>>> complicated View tree with scrolling layers that exceed "normal" container
>>> sizes, it *does* work as expected, so I have to assume the issue is in the
>>> measure pass.
>>>
>>> I've read as much documentation as I can find about what's going on
>>> during the measure and layout passes, and examined the source, but I
>>> believe I must be missing something.
>>>
>>> TYIA.
>>>
>>> --
>>> --
>>> 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
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>>
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>> --
>> --
>> 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
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Android Developers" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/android-developers/Wos0Zu0IdFM/unsubscribe?hl=en
>> .
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
> --
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
--
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
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.