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.