android–ScaleFactor往往是一个

android–ScaleFactor往往是一个,第1张

概述我在自定义视图中有以下代码,它是一个ScaleGestureDetector,我想用它做的是当你捏在屏幕上时改变视图的宽度和高度,但是ScaleFactor总是倾向于一个,我不知道知道如何解释它,但是一秒钟后,ScaleFactor低于/高于1,然后再次成为一个.你可以在logCat输出中看到我在说什么.码:publicc

我在自定义视图中有以下代码,它是一个ScaleGestureDetector,我想用它做的是当你捏在屏幕上时改变视图的宽度和高度,但是ScaleFactor总是倾向于一个,我不知道知道如何解释它,但是一秒钟后,ScaleFactor低于/高于1,然后再次成为一个.你可以在logCat输出中看到我在说什么.

码:

public class simpleOnScaleGestureListener extends SimpleOnScaleGestureListener {    @OverrIDe    public boolean onScale(ScaleGestureDetector detector) {        float ScaleFactor = 1.0f;        ScaleFactor *= detector.getScaleFactor();        // Don't let the object get too small or too large.          ScaleFactor = Math.max(0.1f, Math.min(ScaleFactor, 5.0f));        Log.d("ScaleFactor", "The ScaleFactor is "+ScaleFactor);    return true;    }    @OverrIDe    public voID onScaleEnd(ScaleGestureDetector detector) {    }}

LogCat输出:

05-29 19:37:48.019: D/ScaleFactor(7279): The ScaleFactor is 1.024709105-29 19:37:48.059: D/ScaleFactor(7279): The ScaleFactor is 1.009006905-29 19:37:48.069: D/ScaleFactor(7279): The ScaleFactor is 1.026843505-29 19:37:48.109: D/ScaleFactor(7279): The ScaleFactor is 1.038901905-29 19:37:48.119: D/ScaleFactor(7279): The ScaleFactor is 1.023620205-29 19:37:48.159: D/ScaleFactor(7279): The ScaleFactor is 1.026798805-29 19:37:48.169: D/ScaleFactor(7279): The ScaleFactor is 1.013346805-29 19:37:48.199: D/ScaleFactor(7279): The ScaleFactor is 1.023028305-29 19:37:48.219: D/ScaleFactor(7279): The ScaleFactor is 1.00379205-29 19:37:48.599: D/ScaleFactor(7279): The ScaleFactor is 1.005-29 19:37:48.629: D/ScaleFactor(7279): The ScaleFactor is 1.211067705-29 19:37:48.639: D/ScaleFactor(7279): The ScaleFactor is 1.248642305-29 19:37:48.679: D/ScaleFactor(7279): The ScaleFactor is 1.070995805-29 19:37:48.689: D/ScaleFactor(7279): The ScaleFactor is 1.09461805-29 19:37:49.229: D/ScaleFactor(7279): The ScaleFactor is 1.005-29 19:37:49.259: D/ScaleFactor(7279): The ScaleFactor is 1.203200505-29 19:37:49.269: D/ScaleFactor(7279): The ScaleFactor is 1.168778805-29 19:37:49.309: D/ScaleFactor(7279): The ScaleFactor is 1.060064405-29 19:37:49.319: D/ScaleFactor(7279): The ScaleFactor is 1.060822405-29 19:37:50.049: D/ScaleFactor(7279): The ScaleFactor is 1.005-29 19:37:50.079: D/ScaleFactor(7279): The ScaleFactor is 1.373832305-29 19:37:50.089: D/ScaleFactor(7279): The ScaleFactor is 1.150733505-29 19:37:50.129: D/ScaleFactor(7279): The ScaleFactor is 1.202677505-29 19:37:50.899: D/ScaleFactor(7279): The ScaleFactor is 1.005-29 19:37:50.929: D/ScaleFactor(7279): The ScaleFactor is 1.586241505-29 19:37:50.939: D/ScaleFactor(7279): The ScaleFactor is 1.162107305-29 19:37:52.559: D/ScaleFactor(7279): The ScaleFactor is 1.005-29 19:37:52.599: D/ScaleFactor(7279): The ScaleFactor is 1.009771705-29 19:37:52.599: D/ScaleFactor(7279): The ScaleFactor is 1.0186267

解决方法:

这段代码来自Dragging and Scaling上的AndroID教程,但有一个重要区别:’ScaleFactor’局部变量(旁注 – 约定是用小写字母开始变量名)被声明为整个类的实例/成员变量mScaleFactor在原始代码中(‘m’代表AndroID中的成员).

预期的结果是该行:

ScaleFactor *= detector.getScaleFactor();

将在手势过程中将各个事件比例因子累积为有意义的值,而在您的版本中,它会在每次调用onScale()时重置,因此您只能看到每个单独的缩放事件创建的瞬时值.

如果这仍然有点令人费解,那么请查看基本的Java教科书,以了解不同类型的变量及其范围.

总结

以上是内存溢出为你收集整理的android – ScaleFactor往往是一个全部内容,希望文章能够帮你解决android – ScaleFactor往往是一个所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1106699.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存