【问题标题】:zooming and panning with buttons in android emulator使用 android 模拟器中的按钮进行缩放和平移
【发布时间】:2014-09-02 23:37:09
【问题描述】:

我正在尝试为我的 uni 项目实现缩放功能。所以我的应用程序从 SD 库中加载了一张图片。它有用于缩放和平移的按钮。我必须在模拟器中实现这个项目。

到目前为止,我主要找到了多点触控或捏缩放的解决方案。但我不能使用多点触控,因为模拟器不允许它,这也是我的教授的要求。仅通过鼠标单击按钮,我无法真正找到有关缩放的实质性资源。任何提示从哪里/如何开始?

谢谢!

【问题讨论】:

    标签: android zooming pan


    【解决方案1】:

    好的,在这里我终于想出了一个简单地使用按钮进行缩放的代码。我把它放在这里以防其他人需要这样的东西。但我想它仍然可以优化。例如,如果您需要,该代码缺少平移。缩放也可能不适合您的需求,在这种情况下,您可以随意调整它。

    package com.example.ZoomApp;
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.Matrix;
    import android.graphics.RectF;
    import android.util.AttributeSet;
    import android.widget.ImageView;
    
    public class ZoomInOut extends ImageView
    {
        Matrix matrix = new Matrix();
        float saveScale = 1f;
        float right, bottom, origWidth, origHeight, bmWidth, bmHeight;
    
         public ZoomInOut(Context context, AttributeSet attr){
            super(context, attr);
            setScaleType(ScaleType.MATRIX);
            matrix.setTranslate(1f, 1f);
            setImageMatrix(matrix);
        }
    
        public void ZoomIn () {          
    
            saveScale = saveScale + 0.1f;
            matrix.setScale( saveScale, saveScale );
            setImageMatrix( matrix );
            center(true, true);
            invalidate();
        }    
    
        public void ZoomOut () {         
    
            saveScale = saveScale -  0.1f;
            matrix.setScale( saveScale, saveScale );
            setImageMatrix( matrix );
            invalidate();
        }    
        @Override
        public void setImageBitmap(Bitmap bitmap){
            bmWidth=bitmap.getWidth();
            bmHeight=bitmap.getHeight();
            super.setImageBitmap(bitmap);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-08-13
      • 1970-01-01
      • 2012-08-23
      • 1970-01-01
      • 2016-11-25
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多