Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use zoom controls on TextView in Android ?

 
Pritam Shah
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to zoom text that is displayed at center of screen as per user choice. How can I achieve this ? Using pinch multitouch cannot be tested on emulator and I want something that I can test on Android emulator. Can I use zoom in and out controls to control only text view for my layout ? Or Can I use webview to contain a text as webview has default zoom in out buttons ? Or any better way to acheive this ?
I have also posted this on Stackoverflow here and on anddev here
 
Shawn Franks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your best and easiest way would to be as you though and create a webview to display the text and use the built in zoom, on top of this you also benefit from being able to add a find on page option, and a copy and paste feature that you cant do easily in a plain text view
 
Pritam Shah
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shawn Franks wrote:Your best and easiest way would to be as you though and create a webview to display the text and use the built in zoom, on top of this you also benefit from being able to add a find on page option, and a copy and paste feature that you cant do easily in a plain text view


Yes I had to do the same instead of other alternative of using 2D canvas for this very purpose. I faced issues when i tried to use style with the text in embedded HTML by calling loadData(), which on search I discovered some problems with using loadData() . So using loadDataWithBaseURL() with fake URL solved it. Also webview is strict in checking tags as I had to spend time for a forgotten closed tag which did not allow to use my style element.

I want to now distinguish single and multitouch events on this text element in webview, but using OnTouchListener removes my zoom controls. Does onTouchListener and Zoom Controls cannot coexist ? Any one have faced this issue ?
 
Shawn Franks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pritam Shah wrote:
Shawn Franks wrote:Your best and easiest way would to be as you though and create a webview to display the text and use the built in zoom, on top of this you also benefit from being able to add a find on page option, and a copy and paste feature that you cant do easily in a plain text view


Yes I had to do the same instead of other alternative of using 2D canvas for this very purpose. I faced issues when i tried to use style with the text in embedded HTML by calling loadData(), which on search I discovered some problems with using loadData() . So using loadDataWithBaseURL() with fake URL solved it. Also webview is strict in checking tags as I had to spend time for a forgotten closed tag which did not allow to use my style element.

I want to now distinguish single and multitouch events on this text element in webview, but using OnTouchListener removes my zoom controls. Does onTouchListener and Zoom Controls cannot coexist ? Any one have faced this issue ?


You would need to override the the normal on-touch and then have the zoom trigger when there is a touch up like say when you touch the screen then release where you touched. Also keep in mind multi touch is not supported on 99% of android phones. And yes you need to load a fake url for JavaScript to render properly when using an inputstream, or a string to load the web page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic