问题描述
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在协调器布局中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!