Friday, March 25, 2011

[android-developers] Re: draw text with html format inside a rectangle

Thanks a lot Kostya, that helped so much! DynamicLayout was what I
need, and now it is working.
And lbendin, your list is really usefull too, thanks!

On Mar 19, 8:11 pm, Kostya Vasilyev <kmans...@gmail.com> wrote:
> Fina,
>
> TextView draws text using this:
>
> http://developer.android.com/reference/android/text/Layout.html
>
> - note the draw() method
>
> Specifically, it uses this subclass, which may be only necessary for
> editing (not just drawing):
>
> http://developer.android.com/reference/android/text/DynamicLayout.html
>
> Layout.draw() already handles drawing text that may consist of multiple
> Spannable objects, that's what actually provides support for various
> HTML tags, as listed by lbendin.
>
> It should be possible to use android.text.Layout in your own code. Look
> at TextView source to see how it can be instantiated and how to make it
> draw() itself.
>
> -- Kostya
>
> 19.03.2011 21:50, lbendlin пишет:
>
>
>
> > I thought you are using a textview. I don't know if the canvas
> > actually supports it.
>
> > do something like
>
> >   myTextView.setText(Html.fromHtml(myHtmlString))
>
> > by the way, I found the list of supported tags:
>
> > •br
> > •p
> > •div
> > •em
> > •b
> > •strong
> > •cite
> > •dfn
> > •i
> > •big
> > •small
> > •font
> > •blockquote
> > •tt
> > •monospace
> > •a
> > •u
> > •sup
> > •sub
>
> > On Mar 19, 9:09 am, Fina Perez<fina.pere...@gmail.com>  wrote:
> >> Hi! Thanks for your answer.
> >> For my purpose, I just need the tags you mentioned. The problem is
> >> that when I send the text to the rectangle, it loose the format. I do
> >> something like:
>
> >> CharSequence myString; //it has for example<b>Hello</b>  world
>
> >> //I dont know if this is correct
> >> myString = Html.fromHtml(myString);
>
> >> //and now I paint the text
> >> canvas.drawText(myString,...);
>
> >> But this isn't working, and I can't use a webView(or even a textView)
> >> because I paint my view manually, with canvas and rectangles...I don't
> >> know if there is a way to paint a textView, for example, in a BitMap.
>
> >> On Mar 19, 1:18 pm, lbendlin<l...@bendlin.us>  wrote:
>
> >>> While it is possible, it is also very limited. Only a few HTML tags
> >>> are honoured, like smaller/bigger, bold etc.  I think that even for
> >>> this little functionality you will spend a whole HTML rendering engine
> >>> in memory, and that's just not worth it.
> >>> If you must, use a webview.
> >>> On Mar 18, 11:55 am, Fina Perez<fina.pere...@gmail.com>  wrote:
> >>>> Hi!!
> >>>> I'm trying to paint a rectangle, and inside it, put some text which is
> >>>> "html-format" (sorry for my english, it is so bad ) I use CharSequence
> >>>> (because this supports html) instead of String, and I call drawText
> >>>> with those parameters, but the format isn't painted.
> >>>> Any idea? is it possible?
> >>>> Thanks a lot!- Hide quoted text -
> >> - Show quoted text -
>
> --
> Kostya Vasilyev --http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment