How can I get zoom functionality for images?

后端 未结 13 1423
粉色の甜心
粉色の甜心 2020-11-22 02:13

Is there a common way to show a big image and enable the user to zoom in and out and pan the image?

Until now I found two ways:

  1. overwriting ImageView,
13条回答
  •  忘掉有多难
    2020-11-22 02:29

    Something like below will do it.

    @Override public boolean onTouch(View v,MotionEvent e)
    {
    
        tap=tap2=drag=pinch=none;
        int mask=e.getActionMasked();
        posx=e.getX();posy=e.getY();
    
        float midx= img.getWidth()/2f;
        float midy=img.getHeight()/2f;
        int fingers=e.getPointerCount();
    
        switch(mask)
        {
            case MotionEvent.ACTION_POINTER_UP:
                tap2=1;break;
    
            case MotionEvent.ACTION_UP:
                tap=1;break;
    
            case MotionEvent.ACTION_MOVE:
                drag=1;
        }
        if(fingers==2){nowsp=Math.abs(e.getX(0)-e.getX(1));}
        if((fingers==2)&&(drag==0)){ tap2=1;tap=0;drag=0;}
        if((fingers==2)&&(drag==1)){ tap2=0;tap=0;drag=0;pinch=1;}
    
        if(pinch==1)
    
        {
            if(nowsp>oldsp)scale+=0.1;
            if(nowsp

    For viewing complete program see here: Program to zoom image in android

提交回复
热议问题