简体   繁体   English

Android / Java如何缩放/滚动整个活动? (不是ImageView)

[英]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. 在我的xml布局中,如果重要的话我会使用相对布局。 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: 继承我的.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给了我一个简单的库解决方案!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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