Yes, yes, I know, it's a horrible thing. But I do need an AbsoluteLayout.
To be precise, I need a view that is square, with the sides being as long
as the maximum of width and height. Additionally, I want to position that
view centered horizontally, and aligned with the parent top vertically,
both for portrait and landscape device orientations.
So I declared my custom viewGroup as such
<mySpecialView android:id="@+id/specialview"
android:layout_width="wrap_content" android:layout_height=
"wrap_content"
android:layout_alignParentTop="true" android:layout_centerHorizontal=
"true"/>
I do the actual sizing of the ViewGroup in the onMeasure call
@Override
*protected* *void* onMeasure(*int* widthMeasureSpec,
*int*heightMeasureSpec) {
*int* w = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
*int* h = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
*int* sizeSpec;
*if* (w > h) {
sizeSpec = MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY);
} *else* {
sizeSpec = MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY);
}
*final* *int* count = getChildCount();
*for* (*int* i = 0; i < count; i++) {
getChildAt(i).measure(sizeSpec, sizeSpec);
}
*super*.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
That seems to work fine for the most part. However, the ViewGroup is not
aligned to the top of the parent window, rather its center is the same as
the parent's center. So how can I tell the ViewGroup to align to the top?
And yes, in portrait mode it makes no difference, but it's the landscape
mode that I am trying to get working. I read all the articles about layouts
and watched all the videos, but I get the feeling that I am missing
something really obvious.
--
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