Requestlayout Invalidate Postinvalidate

Source: Internet
Author: User

1, there are several ways to implement view update in Android?

Do you know? In fact, there are two ways to implement view updates in Android, one is invalidate, and the other is Postinvalidate, where the former is used in the UI thread itself, while the latter is used in a non-UI thread.

What do you say? Android provides the Invalidate method for interface refresh, but invalidate cannot be called directly in the thread because he is violating the single-threaded model: Android UI operations are not thread-safe, and these operations must be called in the UI thread. In view of this, if you want to use invalidate refresh, then we have to cooperate with the use of handler, so that asynchronous non-UI thread to go to the UI thread call, if you want to use in a non-UI thread directly to call the Postinvalidate method, This eliminates the hassle of using handler.

2. When is requestlayout used?

When the view determines that it is no longer suitable for an existing zone, the view itself calls this method to require the parent view (the parents) to re-invoke his onmeasure onlayout to reset his position. This is especially appropriate when the view's layoutparameter has changed and its value has not been applied to the view.

Requestlayout Invalidate Postinvalidate

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.