本文介绍了BringToFront在协调器布局中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

Android Studio 2.0 Preview 4

我经常使用BringToFront来使TextView显示在其他控件的前面.

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

文档的 bringToFront()说您必须致电requestlayout invalidate.我可以,但是不起作用.

The Doc's bringToFront() say you have to call requestlayout invalidate. Which I do, but doesn't work.

tvLevel.bringToFront();
tvLevel.requestLayout();
tvLevel.invalidate();

我正在android.support.design.widget.CoordinatorLayout

但是,以下代码确实起作用.但仅支持API 21及更高版本.但是我需要支持API 16.

However, the following code does work. But only supports API 21 and above. But I need to support API 16.

  if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      tvLevel.setTranslationZ(4);
      tvLevel.invalidate();
  }

或通过设置xml属性属性android:translationZ("4dp")起作用.但是,仅适用于API 21

Or by setting the xml attribute property android:translationZ("4dp") works. However, only for API 21

推荐答案

   /**
     * 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.!

这篇关于BringToFront在协调器布局中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 19:25