Search code examples
androidzoomingpantextureview

Zooming and panning TextureView


I tried many examples of how to zoom and pan Views. All they work with different views, imageViews. However I could not find any solution for panning zoomed TextureView. Is there anyone who implemented that feature?


Solution

  • In simple views like ImageView in many implementations canvas is used. Instead of canvas in views whose onDraw() method is final use Matrix. Example:

    On ImageView:

     canvas.translate(x, y);
     canvas.scale(mScaleFactor, mScaleFactor);
    

    On TextureView:

     matrix.postTranslate(x, y);
     matrix.postScale(mScaleFactor, mScaleFactor);
    

    Example in github: link