Sorry if this has been covered, but I have been googling for 3 hours
with no success, so here goes.

Please assume that while being new to android, I believe I know the
basics and have successfully published a nice graphical game (Tairu).
I know about inflating an xml layout and instantiating views that
work.

For my current project, I really just want something similar to the
Windows 'DrawText' function where it will draw a bit of a text inside
an arbitrary rectangle of the surface, and do word wrap within that
rectangles boundaries.  That's what I really WANT, but I can't find
any form of drawText that will wrap.

So, while that's what I WANT, I can accept the thought of
programmatically instantiating a TextView (which wraps beautifully).
But I still need to be able to provide the rectangle, which is highly
dynamic.  (which is why I want to call a form of drawText inside of my
onDraw method).  In this particular case, I have something which is
static to a particular view instance (I mean, the View becomes
visible, the position is set, and does not change after that.  but the
text position is dependent on game state and cannot be pre-determined
inside an XML layout).  So in this one case, I could afford the
expense of runtime recalculation of the layout when the view is
displayed.

OK, fine.  So I do something like this:

                enlistLayout = (AbsoluteLayout) mWarPath.findViewById
( R.id.main_frame );
                mEmpireDescriptionView = new TextView( 
enlistLayout.getContext() );
                enlistLayout.addView(   mEmpireDescriptionView,
                                                mEmpireDescriptionRect.width(),
                                                mEmpireDescriptionRect.height() 
);
                mEmpireDescriptionView.layout(  mEmpireDescriptionRect.left,
                                mEmpireDescriptionRect.top,
                                mEmpireDescriptionRect.right,
                                mEmpireDescriptionRect.bottom );

Pretend you didn't see 'AbsoluteLayout' there, I am desperate and have
tried all possible layout classes

main_frame is defined in my main XML layout (it is the outermost
layout, fills the parent, and, as I said, I've tried all the offered
layouts)

With this code, the textView appears, but along the top of the layout,
and not using the width I provided either.

Adding, out of desperation,

                   enlistLayout.requestLayout();

makes no difference.  In fact, so far, NOTHING has made any
difference.  So I thought, ok, while this seems like a useful thing to
be able to do, I can accept if it can't.  I accept that it is
impossible to provide dimensions in advance and that you have to
override the measure and layout callbacks then requestLayout and in
your overrides, force the final layout for the TextView.

Of course, that is completely unacceptable for my FIRST desire (a
drawText that wraps to a rectangle, called from onDraw as needed).
But the point is I feel something like that OUGHT to work, and it
doesn't, so clearly this is MY fault.

Getting back to what I WANT, I guess I can do it myself by repeated
calls to measure text and parsing the string for spaces until I get
the N characters which fit on the first line, then repeat for
additional lines, calling a normal drawText for each line (and using
textMetrics to determine the vertical offset to the next line.)

But why wouldn't that method already exist?  I promise not to fill the
screen with a zillion calls, and/or to cache pre-rendered text on some
bitmap somewhere if antialiased drawText is too expensive to repeat
frequently.

Where is my head going wrong?

And yes, feel free to weigh in with comments suggesting I just use XML
layout, but tell me how I can change the position and size of the text
view in real time then.

Thanks!

- Dan



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