I've shared my ScrollTextView at http://bear-polka.blogspot.com/2009/01/scrolltextview-scrolling-textview-for.html
Comments are welcomed On Jan 6, 8:36 pm, Xiongzh <zx.zhangxi...@gmail.com> wrote: > The TextPaint worked well to measure the text length in pixel. > I've implemented my ScrollTextView successfully. > Here's my codes to calculate the scrolling length. > Just for your information. > > private void calculateScrollingLen() { > TextPaint tp = getPaint(); > Rect rect = new Rect(); > String strTxt = getText().toString(); > tp.getTextBounds(strTxt, 0, strTxt.length(), rect); > mScrollingLen = rect.width() + getWidth(); > rect = null; > } > > Thank you! > And your website looks sharp! > > On 1月6日, 下午3时11分, "心蓝" <kyowxf2...@gmail.com> wrote: > > > U can use TextPaint class ,and the method in this class is measureText, then > > get one char width! > > Any question u can post topic inhttp://androidos.cc/bbs, > > 2009/1/6 Xiongzh <zx.zhangxi...@gmail.com> > > > > Hi all, > > > > I'll like to know how to calculate the actual pixels a text occupies > > > in the screen from its font size. > > > > Say, my font size of the text in TextView is 20.5px. > > > It doesn't mean that every character of the text occupies 20.5px in > > > the screen, does it? > > > > I'm inheriting android.widget.TextView to implement a TextView which > > > text can be scrolled automatically. Just as the behavior of the HTML > > > <marquee/>. > > > > I need to know the actual pixels the text occupied to determine how > > > far I shall scroll the text. > > > However the getTextSize() * getText().length() is much longer than the > > > actual length of the text, so I can't make the text re-displayed on > > > time. > > > > Thank you in advance for helping me. > > > > BR > > > xion...@beijing, China > > > > dirtybea...@hotmail.com > > > -- > > Welcome to my site about GPhone:http://51gphone.cn > > I am a GFans!!欢迎你来到我的GPhone网站!!http://51gphone.cn > > --~--~---------~--~----~------------~-------~--~----~ 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-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---