BringToFront doesn't work inside a coordinator layout

前端 未结 3 1394
谎友^
谎友^ 2021-01-07 17:17
Android Studio 2.0 Preview 4

I am using to use BringToFront to get a TextView to display in front of the other controls.<

3条回答
  •  忘掉有多难
    2021-01-07 17:29

       /**
         * 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 should be 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)
         */
        public void bringToFront() {
            if (mParent != null) {
                mParent.bringChildToFront(this);
            }
        }
    

    according to this You may missing the line:

    ((View)myView.getParent()).requestLayout();
    

    and it will work, Check it out.!

提交回复
热议问题