Android 如何提前知道fling velocity的距离、时间 根据滑动距离得到velocity
来源:互联网 发布:淘宝双11怎么付款最快 编辑:程序博客网 时间:2024/06/06 09:17
为什么
现在Android提供了fling(velocity)函数,但如果需要fling(distance),fling滑动一段距离呢?
如果需要知道fling(velocity)花了多少毫秒呢?
just do it
根据Android源代码,我们可以通过高中数学来实现这些功能。直接上代码
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mMaximumVelocity = ViewConfiguration.get(context) .getScaledMaximumFlingVelocity(); mMinimumVelocity = ViewConfiguration.get(context) .getScaledMinimumFlingVelocity(); float ppi = context.getResources().getDisplayMetrics().density * 160.0f; mPhysicalCoeff = SensorManager.GRAVITY_EARTH // g (m/s^2) * 39.37f // inch/meter * ppi * 0.84f;// double distanceEs = getSplineFlingDistance(1000);// Log.e("getSplineFlingDistance", "getSplineFlingDistance " + distanceEs);// int velocityRs = getVelocityByDistance(116.64459);// Log.e("getVelocityByDistance", "getVelocityByDistance " + velocityRs); } private static final float INFLEXION = 0.35f; // Tension lines cross at (INFLEXION, 1) // Fling friction private static float mFlingFriction = ViewConfiguration.getScrollFriction(); private static float mPhysicalCoeff; private static float DECELERATION_RATE = (float) (Math.log(0.78) / Math.log(0.9)); private double getSplineDeceleration(int velocity) { return Math.log(INFLEXION * Math.abs(velocity) / (mFlingFriction * mPhysicalCoeff)); } private static double getSplineDecelerationByDistance(double distance) { final double decelMinusOne = DECELERATION_RATE - 1.0; return decelMinusOne * (Math.log(distance / (mFlingFriction * mPhysicalCoeff))) / DECELERATION_RATE; }
//通过初始速度获取最终滑动距离 private double getSplineFlingDistance(int velocity) { final double l = getSplineDeceleration(velocity); final double decelMinusOne = DECELERATION_RATE - 1.0; return mFlingFriction * mPhysicalCoeff * Math.exp(DECELERATION_RATE / decelMinusOne * l); }
//通过需要滑动的距离获取初始速度 public static int getVelocityByDistance(double distance) { final double l = getSplineDecelerationByDistance(distance); int velocity = (int) (Math.exp(l) * mFlingFriction * mPhysicalCoeff / INFLEXION); return Math.abs(velocity); }
//获取滑动的时间 /* Returns the duration, expressed in milliseconds */ private int getSplineFlingDuration(int velocity) { final double l = getSplineDeceleration(velocity); final double decelMinusOne = DECELERATION_RATE - 1.0; return (int) (1000.0 * Math.exp(l / decelMinusOne)); }
使用实例在该项目中哦 https://github.com/smallnew/PullFling
0 0
- Android 如何提前知道fling velocity的距离、时间 根据滑动距离得到velocity
- 如何获取Android RecyclerView滑动的距离
- 如何获取Android RecyclerView滑动的距离
- 如何获取Android RecyclerView滑动的距离
- listview得到滑动距离像素的方法
- Android 自定义Title根据滑动距离动画效果
- Scrollview的滑动距离
- 设置滑动的距离
- 根据滑动距离图片做缩放
- Android获取滑动阈值(系统认为最低的滑动距离)
- android周边搜索 如何得到兴趣点到我的距离
- android listview 计算滑动距离
- android----生成距离1970的时间
- Velocity
- Velocity
- Velocity
- Velocity
- Velocity
- 通过dubbo暴露接口调用方法,及基于zookeeper的dubbo涉及配置文件
- 2462: [BeiJing2011]矩阵模板
- Android json基础
- java thrift开发姿势
- 桌面WPF程序嵌入Unity3D引擎(standalone)并实现通讯
- Android 如何提前知道fling velocity的距离、时间 根据滑动距离得到velocity
- 写能执行cmd命令的bat文件
- Spring Aop 目标对象内部的自我调用无法实施切面的增强处理原因
- 浏览器的工作原理:网络浏览器幕后揭秘
- JS正则表达式大全(整理详细且实用)
- NSString的各种用法,包括扩展名的pathExtension
- centos 7.2安装git2.x版本
- js将小数位不够补足,小数位不够,用0补足位数
- React Native Touchable系列组件