How can I get zoom functionality for images?

后端 未结 13 1182
粉色の甜心
粉色の甜心 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:36

    UPDATE

    I've just given TouchImageView a new update. It now includes Double Tap Zoom and Fling in addition to Panning and Pinch Zoom. The code below is very dated. You can check out the github project to get the latest code.

    USAGE

    Place TouchImageView.java in your project. It can then be used the same as ImageView. Example:

    TouchImageView img = (TouchImageView) findViewById(R.id.img);
    

    If you are using TouchImageView in xml, then you must provide the full package name, because it is a custom view. Example:

    
    

    Note: I've removed my prior answer, which included some very old code and now link straight to the most updated code on github.

    ViewPager

    If you are interested in putting TouchImageView in a ViewPager, refer to this answer.

提交回复
热议问题