Android Control display order control

Source: Internet
Author: User

In Android If a control is added statically in XML first, the rest of the controls are added dynamically via AddView, so if there is a control overlay (for example, using Framelayout or Relativelayout), The controls that are added first are overwritten by the controls that are added later.

In the view class there is a method BringToFront, which has to be annotated as follows:

/**

* Change the View ' s z order in the tree, so it's on top of other sibling

* views. This ordering affect layout, if the parent container

* uses an order-dependent layout scheme (e.g., linearlayout). Prior

* To {@link Android.os.build.version_codes#kitkat} this

* method should is followed by calls to {@link #requestLayout ()} and

* {@link view#invalidate ()} on the View's parent to force the parent to redraw

* With the new child ordering.

*

* @see Viewgroup#bringchildtofront (View)

*/

As we can see, this method can change the order of the ViewGroup in the z coordinate so that the current control is at the top of all sibling controls, at the same time before 4.4, and requires its parent control to call Requestlayout () and Invalidate () To redraw the order of the child controls.

It is also important to note that you need to call BringToFront () to set the order of the specified controls after all the controls have been loaded, or else the control that you want to load will probably overwrite the control you wish to put on.

This way we can arrange the overwrite order of the child controls.

Android Control display order control

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.