Skip to content

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:

  1. Create instance of GestureController.
  2. Add state listener to controller with controller.addOnStateChangeListener() method.
  3. Pass touches from the view to controller with controller.onTouch() method.
  4. Set correct "viewport" and "image" sizes with controller.getSettings().setViewport(w, h) and controller.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 call controller.resetState().
  5. Apply new state received from controller to the view.
  6. 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.

Clone this wiki locally