My layout contains buttons, textviews, etc. Is it possible to implement pinch zoom in my layout?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I implemented a pinch zoom for my
TextView
, using this tutorial. The resulting code is this:and in onCreate():
Magic constants 1.1 and 0.95 were chosen empirically (using
scale
variable for this purpose made myTextView
behave kind of weird).For android 2.2+ (api level8), you can use ScaleGestureDetector.
you need a member:
in your constructor (or onCreate()) you add:
You override onTouchEvent:
If you draw your View by hand, in the onScale() you probably do store the scale factor in a member, then call invalidate() and use the scale factor when drawing in your onDraw(). Otherwise you can directly modify font sizes or things like that in the onScale().
I have an open source library that does this very well. It's a four gesture library that comes with an out-of-the-box pan zoom setting. You can find it here: https://bitbucket.org/warwick/hacergestov3 Or you can download the demo app here: https://play.google.com/store/apps/details?id=com.WarwickWestonWright.HacerGestoV3Demo This is a pure canvas library so it can be used in pretty any scenario. Hope this helps.
Check out the following links which may help you
Best examples are provided in the below links, which you can refactor to meet your requirements.
implementing-the-pinch-zoom-gestur
Android-pinch
GestureDetector.SimpleOnGestureListener
In honeycomb, API level 11, it is possible, We can use setScalaX and setScaleY with pivot point
I have explained it here
Zooming a view completely
Pinch Zoom to view completely
I have created a project for basic pinch-zoom that supports Android 2.1+
Available here