Scaling image of ImageView while maintaining center point in same place

后端 未结 2 969
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 12:03

I have set a prescaled Bitmap as ImageView\'s source. Then I\'ve read Matrix of an ImageView and shift Bitmap of an ImageView via matrix.postTranslate(shi

相关标签:
2条回答
  • 2021-01-03 12:04

    Maybe this can be helpful:

    If you got two fingers on screen, you can get the event of the two fingers and get the mid point:

    PointF mid;
    MotionEvent event;
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    mid.set(x / 2, y / 2);
    

    Then you can set the scalation having the mid point in the center of the screen:

    matrix.postScale(scale, scale, mid.x, mid.y);
    
    0 讨论(0)
  • 2021-01-03 12:08

    Take a look at my question here regarding creating a zoomable ViewGroup. I've described code snippets from my end solution, and some of it might be helpful.

    Extending RelativeLayout, and overriding dispatchDraw() to create a zoomable ViewGroup

    0 讨论(0)
提交回复
热议问题