Basics of view in Android

Source: Internet
Author: User

The bounds of view

View is the interface we see, with four boundaries, Top/left, bottom/right, and coordinate systems from top left to bottom right. These four values can be called gettop ()/get by any of the child classes of the view ... Get.

But the pit-daddy thing is that these cannot be called in the life cycle function, otherwise all returns 0, because the drawing is not finished yet, it can be placed in the Onclicklistener of the button.

Types of events

Divided into motionevent and touchslop, divided into Action_down, Action_move, action_up.

Motionevent is clicked after the event can be Getx ()/gety ()/getrawx ()/getrawy () to get the location of the click, the difference is a relative to the current view, one is relative to the upper left corner of the phone screen.

The touchslop is the smallest sliding distance the system can recognize. can be done by

Velocitytracker speed in the process of using open tracking

The gesturedetector is used to detect user clicks, swipes, long presses, and double-click behavior.

Scroller is used to move objects with elasticity.

How to Scrub

There are 3 main ways of paddling, respectively, by the Scrollto/scrollby method provided by the view itself. The second is to apply a panning effect to the view by animation. The third is sliding by changing the view's layoutparams to make the view re-layout.

First, Scrollto/scrollby only changes the view's content rather than the location of the view itself, and the position of the view itself is constant (GETSCROLLX is changed, but gettop/getleft/getbottom/ GetRight unchanged).

It's a bit simple to use, and it's good for sliding the view content.

The second is animation, which has the advantage of being easy to operate and suitable for non-interactive view and for complex animation effects.

The third is to change the layout parameters, the advantage is applicable to the interactive view, the disadvantage is that the operation is slightly complicated.

Event distribution mechanism

The distribution of click events is the process of distributing the Motionevent event, which is accomplished by three main methods: Dispatchtouchevent (), Onintercepttouchevent (), Ontouchevent ()

As soon as the click event is passed to the current View,dispatchtouchevent method, the relationship between them can be represented by:

    @Override    publicboolean  dispatchtouchevent (motionevent event) {         Boolean false ;         if (Onintercepttouchevent (event)) {            = ontouchevent (event);         Else {            = child.dispatchtouchevent (event);        }         return consume;    }

For Viewlayout, the Order of processing is:

Mainactivity-dispatchtouchevent-action_down
Customlayout-dispatchtouchevent-action_down
Customlayout-onintercepttouchevent-action_down
Custombutton-dispatchtouchevent-action_down
Custombutton-ontouch-action_down
Custombutton-ontouchevent-action_down
Mainactivity-dispatchtouchevent-action_up
Customlayout-dispatchtouchevent-action_up
Customlayout-onintercepttouchevent-action_up
Custombutton-dispatchtouchevent-action_up
Custombutton-ontouch-action_up
Custombutton-ontouchevent-action_up
Custombutton--onclick

For view, the order of processing is:

Mainactivity-dispatchtouchevent-action_down
Custombutton-dispatchtouchevent-action_down
Custombutton-ontouch-action_down
Custombutton-ontouchevent-action_down
Mainactivity-dispatchtouchevent-action_up
Custombutton-dispatchtouchevent-action_up
Custombutton-ontouch-action_up
Custombutton-ontouchevent-action_up
Custombutton--onclick

For more information, please refer to: http://blog.csdn.net/lanhuzi9999/article/details/26515421

Basics of view in Android

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.