2

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!

Scott Nova
  • 43
  • 1
  • 8
  • 2
    Maybe you could use the GestureFrameLayout from [this library](https://github.com/alexvasilkov/GestureViews/wiki/Usage) as root in your view. I didn't try it myself but it seems to be what are you looking for. – MoQ93 Apr 03 '17 at 21:53
  • @Rotwang this worked perfectly! I can't tell you how long I searched for a smooth solution. Now I hope it just works on tablets. Thanks again! – Scott Nova Apr 03 '17 at 22:55
  • 1
    Wrong credits. Credits go to @MoQ, not me. – Phantômaxx Apr 04 '17 at 06:47
  • lol sorry guys.. thats weird I could have sworn i saw your name tagge ... Thanks @MoQ !!!! – Scott Nova Apr 05 '17 at 08:43
  • @ScottNova no problem, glad it helped you! :) – MoQ93 Apr 06 '17 at 12:34

1 Answers1

0

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

Scott Nova
  • 43
  • 1
  • 8