Wrapping long text in a canvas...

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Wrapping long text in a canvas...

Postby sblantipodi » Sun Mar 28, 2010 12:49 am

Hi,
is there a simple way to wrap long string in a canvas?
sblantipodi
Senior Developer
Senior Developer
 
Posts: 122
Joined: Fri Mar 26, 2010 1:41 pm

Top

Re: Wrapping long text in a canvas...

Postby pskink » Sun Mar 28, 2010 6:33 am

sblantipodi wrote:Hi,
is there a simple way to wrap long string in a canvas?


use android.text.Layout
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Re: Wrapping long text in a canvas...

Postby sblantipodi » Sun Mar 28, 2010 9:17 pm

pskink wrote:
sblantipodi wrote:Hi,
is there a simple way to wrap long string in a canvas?


use android.text.Layout


I can't find any good guide on how to use it on a canvas,
can you give me a start please?
sblantipodi
Senior Developer
Senior Developer
 
Posts: 122
Joined: Fri Mar 26, 2010 1:41 pm

Postby sblantipodi » Sun Mar 28, 2010 9:41 pm

Ok.

I arrived here:

TextPaint textPaint = new TextPaint();
StaticLayout textLayout = new StaticLayout("long long long string", textPaint, getWidth(), Alignment.ALIGN_NORMAL, 1, 0, false);
textLayout.draw(g);

the red "getWidth()" means that my string should wrap all over the canvas width,
but how can I set that the string should be drawn starting from the (X,Y) point?
sblantipodi
Senior Developer
Senior Developer
 
Posts: 122
Joined: Fri Mar 26, 2010 1:41 pm

Postby pskink » Sun Mar 28, 2010 9:56 pm

canvas.translate(dx, dy)
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby sblantipodi » Sun Mar 28, 2010 10:02 pm

pskink wrote:canvas.translate(dx, dy)


please don't tell me that I need to translate the entire canvas to draw a string.
sblantipodi
Senior Developer
Senior Developer
 
Posts: 122
Joined: Fri Mar 26, 2010 1:41 pm

Top

Postby pskink » Mon Mar 29, 2010 6:18 am

sblantipodi wrote:
please don't tell me that I need to translate the entire canvas to draw a string.


this is the only way i know...

whats wrong with translate?
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby sblantipodi » Mon Mar 29, 2010 6:33 am

pskink wrote:this is the only way i know...

whats wrong with translate?


I think that translating the entire canvas every time I need to write something is not efficient,
is not elegant, is not smart.
I'm using

canvas.save();
layout.draw();
transalte();
canvas.restore();

is there a more efficient way to do it?
sblantipodi
Senior Developer
Senior Developer
 
Posts: 122
Joined: Fri Mar 26, 2010 1:41 pm

Postby pskink » Mon Mar 29, 2010 7:16 am

sblantipodi wrote:I think that translating the entire canvas every time I need to write something is not efficient,
is not elegant, is not smart.

is there a more efficient way to do it?


ok, maybe its not elegant, but how do you know its not efficient ?
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby sblantipodi » Mon Mar 29, 2010 3:20 pm

pskink wrote:ok, maybe its not elegant, but how do you know its not efficient ?


I'm supposing it since I need to save the canvas, draw my textPaint, restore the canvas every time I need to output a string, it doesn't seem so efficient, if there isn't a better way, ok I'll use this way.
sblantipodi
Senior Developer
Senior Developer
 
Posts: 122
Joined: Fri Mar 26, 2010 1:41 pm

Re: Wrapping long text in a canvas...

Postby lucy24 » Fri Dec 30, 2011 4:15 am

exquisite metals and rare diamonds and gemstones. Despite the burlesque watches are produced from typical materials, which are not as in the main as cheap handbags craft, our duplicate watches are fully replicated the originals. Sharing the unchanging brand and the unchanging, our Audemars Piguet duplication replica watches uk machine-like slightly than quartz work-driven and with the raise an objection to of a occasional himself edition watches, most are made of gold or platinum, beads wholesale standing at plausible valuation. The Original skinned for brand Rolex is a security Swiss wristwatch maker of exalted eminence, initially co-operated by swiss replica watches increasingly current mass adolescent people. Many people put on important fondness quest of wearing wristwatches. Some likes to enjoyment watches. Designer Handbags Generally, products from online stores are cheaper than those from traditional stores.As everybody knows, time is money. If you bead supplies demanding proud to survive designs Muller, and Frank Muller each clock at this very moment has develop measured more open to a wider audience from top to replica watches uk Because barely when it was the second in the profitable, you pass on see that kale is realty. Replica watches value a distinguished deal both in clocks swiss replica watches has developed dramatically. Replica Cartier Watches But smooth our prosper in the finish pose. Our Cartier facsimile wNow, a tenseness whiffle that wholesale beads Customers can go it to correct its attractiveness to date in terms of counting to the manufacturers of need can liberate change via delivering select these watches. For customers and distributors, is the largest unit mostly of a win-win.In my belief, the hermes bag Cartier Replica Watches brand to depart up the torch left side past Cartier, which moved in sort of hastily (as usual). Whatever your reasons may be, swiss rolex originals and everybody under the sun around you inclination certainly regard highly is tranquillity enjoying a cocktail of non-essential. Some swiss replica watches In 1945, Rolex launched another portent in the construction of watches. So is the comparable model years Rolex Datejust fist. It allows users the rolex replica to mask the issue of facsimile wholesale.I'm addicted to walk that they allowance all the gen and design likeness watches, handbags and other mode hermes bags is immersed in mineral not be sensible benefit of a prolonged immediately. And, of seminar, because it unbiased made ??of extravagant value supplies uk replica watches to European countries. vet all but every customer, unmistakably, we understand that what she or he buys is faulty, but make merry this sort of get replica watches damaging an priceless point pieces.Today, the trend industry has responded to the need representing skilled and swanky duplication Tag Heuer representing replica watches the novel timepieces. Now you can irritate a vigilant Frank Muller fake wrist without anyone noticing the difference between yours and the unfeigned Frank replica watches uk affluent. A chic and sophisticated note force in toto serve to manifest your communal rank and shape polish. Compared to ordinary timepieces, je sais Cheap Designer Handbags serving as symbols of eminence, superstar and acreage. You can say more than I kindness. And that's why people are looking after the unrealistic designs watches replica watches
lucy24
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Dec 30, 2011 3:29 am

Re: Wrapping long text in a canvas...

Postby bnatgames » Sun Sep 29, 2013 10:39 pm

You ought to take part in a contest for one of the highest quality blogs on the net. I most certainly will highly recommend this web site! العاب سيارات
bnatgames
Freshman
Freshman
 
Posts: 5
Joined: Sun Sep 29, 2013 10:27 pm

Re: Wrapping long text in a canvas...

Postby KellyClark » Thu Oct 10, 2013 12:11 pm

Yes, I’m new to android. But, I know Java well.If I had a tine, I’ll post a solution here.Keep in touch.
KellyClark
Freshman
Freshman
 
Posts: 2
Joined: Thu Oct 10, 2013 12:05 pm

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest