Please suggest a way to zoom all the contents of the edittext when a pinch gesture is detected. Want to zoom like typical text editor apps like KingSoft and quickoffice.
-
Got it mate, I'm new to this place. – Prithiv Raj Feb 04 '14 at 08:10
3 Answers
It's going to be nasty, but you can subclass EditText
.
In your subclass, override onTouch
and pass its values to a ScaleGestureDetector
. Store the detected scale as a member variable.
Override onDraw
, and call canvas.scale()
with your scale value prior to calling through to super.onDraw
.
This is likely to wreak havoc with the caret and edit controls.

- 1,383
- 11
- 16
-
-
1ok, what you will do with Selections Handles? it's shows as the PopupWindows. And doesn't calculate View#setScale, so drag&drop wouldn't work, text selection will work like without scale. Pins will be appear in places like not scaled – Yevgen Kulik Mar 06 '14 at 15:54
-
1As I said, "This is likely to wreak havoc with the caret and edit controls." – tad Mar 08 '14 at 00:31
I wrote a simple library to do just that, back when I need the functionality in an app. You can find it on GitHub

- 4,668
- 5
- 30
- 41
-
Hello, i have a little problem while implementing your library. Please kindly help me : http://stackoverflow.com/questions/24603282/custom-pinch-to-zoom-edittext-cant-be-edited – Blaze Tama Jul 07 '14 at 04:59
To add tad's answer, you probably can use children of MetricAffectingSpan or CharacterStyle: http://developer.android.com/reference/android/text/style/MetricAffectingSpan.html
You will have to handle copy/paste (with spans!), and it will be tedious.
Note that you can derive your own spans from the existing classes, but I cannot say what will happen with them when you copy & paste the text into another application.
OTOH, if you decide from the very beginning that your text is just plain text and there is only one span used for zooming, it may be not so tedious.

- 16,368
- 4
- 94
- 127