Custom Controls (2.2): SurfaceView and SurfaceHolder,

Source: Internet
Author: User

Custom Controls (2.2): SurfaceView and SurfaceHolder,
In this example, the requirement and process are as follows: The Activity loads the custom SurfaceView-> SurfaceView constructor to start thread A and cyclically change the x and y coordinates of SurfaceView. When x, when the y coordinate arrives at A certain point, set the gradient flag picAlphaFlag to true-> when the Surface is created, that is, surfaceCreated. Start thread B. The loop is based on x and y of SurfaceView (changed by thread A loop) when the position of the graph is drawn in real time and picAlphaFlag is true, the other graph is gradually displayed.
This example can be optimized (personal opinion): 1. Thread A and thread B can be merged;
Revelation in this example: 1. surfaceView is usually customized; 2. surfaceView is usually configured with more than one sub-thread to execute time-consuming operations such as drawing; 3. surfaceView usually implements SurfaceHolder. callback interface, mainly used to manage the life cycle surfaceCreated and surfaceDestroyed; Demo

Related Article

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.