"Android Development Art Quest" notes-(3) View Event System

Source: Internet
Author: User

View Basics

View is the base class for all controls in Android, and ViewGroup inherits view.
In Android, the x-axis and y-axis are in the right and bottom squares, respectively.

Position parameters:
(left , top   ): View 左上角原始坐标(right, bottom): View 右下角原始坐标(x    , y     ): View 左上角最终坐标translationX: View 左上角横向偏移量translationY: View 左上角纵向偏移量x = left + translationXy = top  + translationY (setX/Y() 时其实就是改变 translationX/Y 的值)width  = right  - leftheight = bottom - top
Motionevent and Touchslopmotionevent

Typical event: Action_down, Action_move,action_up
The meaning is easy to understand, namely, falling, moving, starting

A single touch triggers a sequence of events:

    • Tap the screen and leave the release: down--up
    • Click on the screen to swipe and release: down, move->...-> move, up

Get the coordinates of the Click event via motionevent:

    • Getx/gety: x and Y coordinates relative to the upper-left corner of the current View
    • Getrawx/getrawy: x and Y coordinates relative to the upper-left corner of the phone screen
Touchslop

The minimum distance to slide, if not reached, is not considered sliding, the default 8DP.

Velocitytracker, Gesturedetector and Scrollervelocitytracker

Speed tracking, used to track the speed of your finger during the sliding process.

In the Ontouchevent method of the View:

VelocityTracker velocityTracker = VelocityTracker.obtain();velocityTracker.addMovement(event);velocityTracker.computeCurrentVelocity(1000);// 1000ms内划过的像素数int xVelocity = (int) velocityTracker.getXVelocity();int yVelocity = (int) velocityTracker.getYVelocity();

Recovery:

velocityTracker.clear();velocityTracker.recycle();
Gesturedetector

Gesture detection, which is used to assist in the detection of user clicks, swipes, long presses, double-clicks, and other behaviors.
General listening and sliding correlation, in the ontouchevent self-realization, if the listening double-click, then use Gesturedetector.

Scroller

The elastic sliding object, which is used to realize the elastic slide of the view, which is the sliding of the transition effect, is used in conjunction with the view's Computescroll method.

"Android Development Art Quest" notes-(3) View Event System

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.