简体   繁体   中英

Android/Java How to Pinch To Zoom/Scroll an entire activity? (NOT an ImageView)

How can I pinch to zoom (smoothly) and scroll around my entire activity screen? I've found dozens of post that talk about pinch to zoom for an ImageView but thats not what I'm trying to do. In my activity I have an image, text, and buttons. I want them all to scale evenly when the user pinches to zoom or scrolls.

In my xml layout I'm using a relative layout if that matters. Currently I found a function to zoom in and out of the entire activity (on tap only) but its not smooth and doesn't allow me to scroll around the screen. Is there a way of adding to my current code or is there another way of doing this? Thanks

Heres my current code in my .java:

public class MapActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);

    View view =getLayoutInflater().inflate(R.layout.activity_map,null); 
    setContentView(view);

    view.setOnClickListener(new View.OnClickListener() {
        float zoomFactor = 1.3f;
        boolean zoomedOut = false;

        @Override
        public void onClick(View v) {
            if(zoomedOut) {
                v.setScaleX(1);
                v.setScaleY(1);
                zoomedOut = false;
            }
            else {
                v.setScaleX(zoomFactor);
                v.setScaleY(zoomFactor);
                zoomedOut = true;
            }
        }
    });

Any help would be appreciated. Thanks

Solved : @MoQ gave me an easy library solution using GestureFrameLayout from this library !

解决:@MoQ使用来自这个库的 GestureFrameLayout给了我一个简单的库解决方案!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM