Android imageviewscaletype矩阵不修改图像第一次执行

发布于 2024-11-19 07:31:02 字数 1203 浏览 1 评论 0原文

我有一个图像视图,我正在尝试在双击上进行缩放。

代码每次都会运行,并正确运行正确的条件,大时变小,小时变大...

但奇怪的是,第一次运行代码运行时,它显示它正在运行 getsmall,但图像本身永远不会缩小。第二次它运行规模到大,我不知道这是否有效,因为图像在执行之前已经很大了。但是在第三次执行时,它再次运行 makesmall条件下,图像会缩小,从那时起,图像在屏幕上按预期放大和缩小。

这个imageview的scaletype是CENTER,是的,minScale在第一次尝试缩小时的值不是1..事实上log显示它的值为0.26...所以这并不是说minScale第一次为零通过。

            @Override
        public boolean onDoubleTap(MotionEvent e) {
            // TODO Auto-generated method stub
            setScale(globalIV);

            System.out.println("DOUBLE TAP "+minScale);
            Matrix mtrx = new Matrix();
            if(!small){
                System.out.println("MAKING SMALL");
                       mtrx.postScale(minScale, minScale);                                          small=true;
            }
            else{
                            mtrx.postScale(1, 1);
                mtrx.postTranslate(minx,miny);
                System.out.println("MAKING LARGE");
                small=false;
            }

                 globalIV.setImageMatrix(mtrx);
            globalIV.setScaleType(ScaleType.MATRIX);
            globalIV.invalidate();

            return false;
        }

有什么想法吗?

I have an imageview that I am attemtping to scale on doubletap..

The code runs everytime and properly runs the right condition, make small when its big and make big when its small...

The odd thing is though, the first time the code is run, it shows its running the getsmall, but the image itself never shrinks.. The second time it runs the scale to big, which I have no idea if this works or not since the image is already large before that execution.. but on the third execution it again runs the make small condition, and the image scales small, and from that point onward the image scales bigger and smaller on the screen as expected.

This imageview is instnatiated with a scaletype of CENTER, and yes minScale has a value other than 1 the first time it tries to shrink.. in fact log shows its value to be 0.26... So its not that the minScale is zero first time through.

            @Override
        public boolean onDoubleTap(MotionEvent e) {
            // TODO Auto-generated method stub
            setScale(globalIV);

            System.out.println("DOUBLE TAP "+minScale);
            Matrix mtrx = new Matrix();
            if(!small){
                System.out.println("MAKING SMALL");
                       mtrx.postScale(minScale, minScale);                                          small=true;
            }
            else{
                            mtrx.postScale(1, 1);
                mtrx.postTranslate(minx,miny);
                System.out.println("MAKING LARGE");
                small=false;
            }

                 globalIV.setImageMatrix(mtrx);
            globalIV.setScaleType(ScaleType.MATRIX);
            globalIV.invalidate();

            return false;
        }

Any Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文