Scaling image of ImageView while maintaining center point in same place

后端 未结 2 958
佛祖请我去吃肉
佛祖请我去吃肉 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);
    

提交回复
热议问题