当前位置:网站首页>Velocitytracker use
Velocitytracker use
2022-06-24 03:02:00 【Study hard】
1 brief introduction
VelocityTracker Speed tracking for touch events , It can obtain the speed value of the current touch event , According to the speed value , We can judge whether the current gesture is fling etc. . Usually used to implement fling Sliding effect when , It makes the control look silky and smooth .
2 Introduction of usage
Let's start with VelocityTracker Class is provided externally API Interface
static VelocityTracker obtain() // obtain VelocityTracker object void addMovement(MotionEvent event) // Add touch events that need to track speed , It can be ACTION_DOWN, ACTION_MOVE, ACTION_UP Any one of /** * Used to calculate the speed of added Events , * units Is the unit of speed , Usually set to 1000, It means the speed of calculation , Unit is pixel / second * maxVelocity Is the maximum speed , */ void computeCurrentVelocity(int units, float maxVelocity) void computeCurrentVelocity(int units) /* * obtain id The speed of the corresponding finger in the horizontal direction , Call... Before using this method computeCurrentVelocity() */ float getXVelocity(int id) float getXVelocity() /* * obtain id The speed of the corresponding finger in the vertical direction , Call... Before using this method computeCurrentVelocity() */ float getYVelocity(int id) float getYVelocity() void clear() // Reset velocityTracker, Go back to the original state void recycle() // Recycle and reuse
Usage is as follows , With onTouchEvent For example
Private VelocityTracker mVelocityTracker;
public void onTouchEvent(MotionEvent ev) {
...
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
switch (ev.getAction()) {
...
case MotionEvent.ACTION_UP:
mVelocityTracker.addMovement(ev);
mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
float velocityX = mVelocityTracker.getX();
float velocityY = mVelocityTracker.getY();
...
}
...
}3 summary
VelocityTracker Class is through jni The way , stay native The velocity calculation of the layer . When using the application layer , When it is really necessary to calculate the speed , Call again addMovement() and computeCurrentVelocity() Method , After all, these are time-consuming methods . Refer to the example above .
边栏推荐
- Instructions for performance pressure test tool
- Easycvr cannot be played when cascaded to the superior platform. Troubleshooting
- What is the difference between cloud desktop cloud terminal and server? What are the advantages of cloud desktop?
- How does easydss solve the problem that the concurrency is too large and the disk read / write cannot keep up?
- Precautions for VPN client on Tencent cloud
- Build a reliable, scalable and maintainable application system
- Prompt error when Jekyll runs cannot load such file -- webrick (LoadError)
- Wkwebview audio and video media playback processing
- October 27, 2021: curriculum. You must take numcourses this semester
- Why enterprises need fortress machines
猜你喜欢

2022-2028 global third-party data platform industry research and trend analysis report

2022-2028 global anti counterfeiting label industry research and trend analysis report

2022-2028 global genome editing mutation detection kit industry survey and trend analysis report
![[51nod] 3047 displacement operation](/img/cb/9380337adbc09c54a5b984cab7d3b8.jpg)
[51nod] 3047 displacement operation
![[summary of interview questions] zj6 redis](/img/4b/eadf66ca8d834f049f3546d348fa32.jpg)
[summary of interview questions] zj6 redis

What is etcd and its application scenarios
![[51nod] 2106 an odd number times](/img/af/59b441420aa4f12fd50f5062a83fae.jpg)
[51nod] 2106 an odd number times

IOS development - multithreading - thread safety (3)

2022-2028 global aircraft audio control panel system industry research and trend analysis report
![[51nod] 2653 section XOR](/img/2d/cb4bf4e14939ce432cac6d35b6a41b.jpg)
[51nod] 2653 section XOR
随机推荐
Cloud call: one line of code is directly connected to wechat open interface capability
New Google brain research: how does reinforcement learning learn to observe with sound?
AI intelligent analysis is innovated again. In the future, the technical reserve of the security industry will become the top priority
Using the database middleware MYCAT to realize read-write separation (dual master and dual slave)
Simple and beautiful weather code
Building a web site -- whether to rent or host a server
What is the use of cloud desktop security server configuration? What should I do?
Pod abnormal troubleshooting
11111dasfada and I grew the problem hot hot I hot vasser shares
The cost of on-site development of software talent outsourcing is higher than that of software project outsourcing. Why
How to set up a cloud desktop server? Is there a charge for cloud desktop server setup?
AI talk | solution for shopping mall inspection robot
[51nod] 3395 n-bit gray code
Iranian gas station paralyzed by cyber attack, babuk blackmail software source code leaked | global network security hotspot
Tke single node risk avoidance
Face recognition using cidetector
Industry ranks first in blackmail attacks, hacker organizations attack Afghanistan and India | global network security hotspot
2022-2028 global cancer biopsy instrument and kit industry research and trend analysis report
What are the security guarantees for cloud desktop servers? What are the cloud desktop server platforms?
[51nod] 2653 section XOR