-
Notifications
You must be signed in to change notification settings - Fork 386
Custom views
Alex Vasilkov edited this page Oct 22, 2015
·
2 revisions
Sometimes it may not be possible to use GestureImageView
or GestureFrameLayout
, or you may need a very special things to happen when user interacts with your view.
In this case you will need to add GestureController
to your view manually. There are few steps to do so:
- Create instance of
GestureController
. - Add state listener to controller with
controller.addOnStateChangeListener()
method. - Pass touches from the view to controller with
controller.onTouch()
method. - Set correct "viewport" and "image" sizes with
controller.getSettings().setViewport(w, h)
andcontroller.getSettings().setImage(w, h)
.
In this case "viewport" is an area in which "image" will be drawn.
When viewport or image size is changed you will need to callcontroller.resetState()
. - Apply new state received from controller to the view.
- The view may also need to implement interfaces like
GestureView
,ClipView
,AnimatorView
if you'll want to add animations to it.
Note: if you want to use your view inside ViewPager consider using GestureControllerForPager
instead.
Refer to GestureImageView
, GestureFrameLayout
and GestureTextView
sources for more details.