Gety, Getscrollx in Getrawx, Getrawy and Getx, getscrolly, and view in diagram Motionevent

Source: Internet
Author: User
Tags gety

The difference between 1.getRawX, Getrawy and Getx, gety

in writingAndroidcustom controls, or when judging user gestures, you often need to use themotioneventin thegetrawx (),Getrawy ()with theGetX (),GetY ()get touch points inXAxis andYThe distance on the axis, all four methods return afloatthe parameter of type, in pixels (Pixel). getrawx (),Getrawy ()returns the position of the touch point relative to the screen, andGetX (),GetY ()The return is the touch point relative to theViewthe location.

The following two graphs visually show the difference between these methods, place a Buttonin the center of the screen,and register the Ontouchlistener for it , and theGreen Circle point in the figure is the touch point position.

GETSCROLLX, getscrolly in 2.View

The value of GETSCROLLX () and getscrolly () is generated by calling view's Scrollto (int x, int y) or scrollby (int x, int y), where Scrollto moves the contents of the view to the specified coordinates x, y , this x, Y is relative to the

The upper-left corner of the view, not the upper-left corner of the screen. Scrollby (int x, int y) changes the relative position in the view, and the parameter x, Y is the relative position of the previous distance.

Text interpretation is always difficult to understand, then we directly, intuitive some.

(Fig. 1) (Fig. 2) (Fig. 3)

1. In Figure 1, a button is placed in the center of the screen, and the button content is placed in its upper-left corner.

2. Call the button's Scrollto (-100,-100) method, as shown in result 2, where the contents of the button are moved to the upper-left corner of the button ( -100,-100)

3. Call the Scrollby ( -100,-100) method to the button in Figure 2, as shown in result 3, the contents of the button are moved to the position relative to Figure 2 ( -100,-100)

The values for GETSCROLLX () and getscrolly () are:

06-15 15:44:56.072  20471-20471/com.test.yangy.studiotest v/scrollactivity:btn scroll x=-20006-15 15:44:56.072  20471-20471/com.test.yangy.studiotest v/scrollactivity:btn Scroll y=-200

It is important to note that when the contents of the view move to the right, the value of GETSCROLLX () is negative, and in the same vein, the negative number is passed to Scrollto and Scrollby x, and the contents of the view move to the right and vice versa to the left.

When the contents of the view Move down, the value of getscrolly () is negative, and in the same vein, a negative number is passed to Scrollto and Scrollby y, and the contents of the view Move down and vice versa.

Gety, Getscrollx in Getrawx, Getrawy and Getx, getscrolly, and view in diagram Motionevent

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.