Marcus Ataide
Marcus Ataide

Reputation: 7540

How to enable zoom in ScrollView?

How to enable zoom in Scrollview?

Here is an application that uses this function very well and works in API9 and more:

The zoomcontrol hide after 2 seconds without user interaction.

enter image description hereenter image description here

Upvotes: 1

Views: 2946

Answers (1)

biddulph.r
biddulph.r

Reputation: 5266

The view you are seeing is a WebView as mentioned by Waza_Be in their comment.

If you want to implement something like this in Android, you can either use a WebView yourself and add text/images etc to this as HTML code. See Building Apps In WebView.

If you absolutely have to use ScrollView you will have to create your own custom implementation.

You could have a RelativeLayout that contains the ScrollView and the two Buttons for zooming in and out. Have the Buttons in their own LinearLayout with orientation="horizontal" and set this to align with the bottom right of the parent RelativeLayout.

That will give you the floating buttons above the ScrollView.

You can then detect a tap on the ScrollView, or when it scrolls using the example given in this StackOverflow article (ScrollView does not support an OnScrollListener as such).

When you detect a scroll/tap, you can then set the Button layout to be visible, and remove visibility after 2 seconds with a Timer or a Thread that sleeps for 2000ms.

To achieve zooming, you would have to increase the of the TextView font size for each (+) click and decrease it for every (-) click. For Bitmaps you could similarly scale the Bitmap to fill the new size.

A lot of work for what you want to achieve. Try to stick to WebView or find another way of representing your application.

Upvotes: 2

Related Questions