Android control display Sequence Control and android control sequence

Source: Internet
Author: User

Android control display Sequence Control and android control sequence

In android, if a static control is added in xml, and the remaining controls are dynamically added through addView, if the control overwrites (for example, FrameLayout or RelativeLayout ), the added control will be overwritten by the added control.

In the View class, there is such a method bringToFront, which has to be noted as follows:

/**

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

* Views. This ordering change may 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 shoshould be followed by cballs 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)

*/

We can see that this method can change the subcontrol order of ViewGroup In the Z axis, so that the current control is at the beginning of all the sibling controls, and the version is obtained before 4.4, you also need its parent control to call requestLayout () and invalidate () to re-draw the subcontrol order.

Note that you must call bringToFront () to set the control sequence after all the controls are loaded, otherwise, the loaded control may overwrite the control you want to mention.

In this way, we can use this method to arrange the subcontrol overwrite sequence.


How can I adjust the stacked order of controls in the android program?

This is simple. When you click imageview2, you first get the location of 2:
Suppose the layout of the outermost layer is AbsoluteLayout abslayout,
AbsoluteLayout. LayoutParams params = (AbsoluteLayout. LayoutParams) imageview2.getLayoutParams ();
Get this params,
Then abslayout. removeView (imageview2 );
Then abslayout. addView (imageview2, params );
In this way, imageview2 is displayed at the beginning.

Let's try it. If you want to do that, give me more points!

For android, I have hidden a control, controlled by a button, and clicked to display the control

Two ideas are provided: 1. Code layout. Note that the Code layout is not in XML. Click the event and re-layout.
2. It is a bit opportunistic, that is, to create an Activity and set the layout as the style you want after clicking it. it is OK to jump to this Activity after clicking Intent. The first type requires knowledge and is relatively complicated.

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.