View and viewgroup Painting Process, gesture listening sequence and usage

Source: Internet
Author: User

One view: the rendering process of viewgroup
Viewgroup painting involves two steps: 1. Measure 2. Layout
Call the callback function in these two steps: 1. onmeasure () 2. onlayout ()

1. onmeasure () in this function, viewgroup will accept the size of the childview request, and store it in childview through the measure (newwidthmeasurespec, heightmeasurespec) function of childview, so that getmeasuredwidth () of childview ()
The value of andgetmeasuredheight () can be obtained by subsequent work.

2. onlayout () in this function, viewgroup will get getmeasuredwidth () and getmeasuredheight () of childview to layout all childview.

3. View. measurespec and layoutparams are used to negotiate the sizes of viewgroup and childview. Here, view. measurespec is used by viewgroup to deploy childview, and layoutparams is used by childview to tell the viewgroup where I need it.

4. At the end of onmeasure of the view, call setmeasureddimension () to store the size of the view. This method determines the size of the current view.


Second view: the sequence and usage of viewgroup gesture monitoring
Callback Function of the view gesture listener: ontouchevent ()
Callback functions related to viewgroup gesture listening: ontouchevent (), onintercepttouchevent ()

1. Both callback functions return a Boolean variable, indicating whether the gesture is consumed. If consumption is completed, true is returned. If consumption is not performed, false is returned.

2. When you touch the screen, a motionevent is generated, and onintercepttouchevent () of viewgroup accepts this motionevent.

If this callback function returns true, it indicates that this viewgroup consumes this gesture and does not want to allow its childview to process it any more. The childview ontouchevent () will no longer accept this gesture, at the same time, the ontouchevent () of this viewgroup accepts this gesture.

If this callback function returns false, it indicates that this viewgroup has not consumed this gesture and wants its childview to process it. childview's ontouchevent () accepts this gesture, at the same time, the ontouchevent () of this viewgroup does not accept this gesture.

3. The ontouchevent () value indicates that the event is passed up, And the onintercepttouchevent () value indicates that the event is passed down.

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.