Slide of view

Source: Internet
Author: User

First, the view's positional parameters (are relative to the parent container's location)

The position of 1.View is determined by the upper-left corner, the lower-right corner point. The corresponding (upper left X-getleft, upper left y-gettop, lower right x-getright, lower right y-getbottom).

2.View offset (translation): Indicates the offset of the upper-left corner relative to the parent container (the difference between the current position and the moved position is called an offset), which defaults to 0. (The test can only be changed by settranslation translation, the motion tween animation.xml invalid) through gettransaltion get x, y

3.View getx (), GetY (all the points in the upper-left corner): x = left + Translationx, the x-coordinate of the upper-right corner plus the x offset, y = top + translationy, (the coordinate of the upper-left corner, plus y offset)

4.View Getscalex (), Getscaley (): The coordinates of the upper-left corner of the view's contents.

Explain:

Ii. introduction of Velocitytracker, Gesturedetector, Scroller

1.VelocityTrancker

Action: Speed tracking, used to track the speed of the finger during sliding (both horizontal and vertical speed)

Use: ①, adding event events to the Velocity object ②, setting time: Refers to the number of pixels that have crossed over a period of time ③, gets the x, y direction (positive from left to right, positive from top to bottom)

Instance:

 Public classMainactivityextendsappcompatactivity {Private Static FinalString TAG = "Mainactivity"; PrivateVelocitytracker Mvelocitytracker =NULL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); //Get VelocityMvelocitytracker =Velocitytracker.obtain (); } @Override Public Booleanontouchevent (Motionevent event) {//the event object is in the charge of the objectmvelocitytracker.addmovement (event); Switch(Event.getaction ()) { CaseMotionevent.action_move://set the time interval: speed refers to the number of pixels that a finger has crossed over a period of timeMvelocitytracker.computecurrentvelocity (1000); //Print SpeedLOG.D (TAG, "slide x pixels in 1 Seconds" +mvelocitytracker.getxvelocity () + "y pixels" +mvelocitytracker.getyvelocity ());  Break; default:                 Break; }        return Super. Ontouchevent (event); }}
mainactivity

Note: When the Getxvelocity () method is called, the average speed is returned. (Suppose I set 1 meow, which means not to wait a second before returning to Getxvelocioty (), but when you call Getxvelocity () to use math to calculate the speed per second).

Slide of view

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.