bringToFront()
为我工作android.support.design.widget.CoordinatorLayout
.我的环境:
Android Studio 1.5.1
设备:摩托罗拉与Android 4.1.2(API 16)
activity_main.xml中:
MainActivity.java:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = (TextView) findViewById(R.id.textView); textView.bringToFront(); }
以下是截图:
同 textView.bringToFront();
没有 textView.bringToFront();
/** * 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); } }
根据这个你可能会错过这一行:
((View)myView.getParent()).requestLayout();
它会工作,检查出来.!
在KITKAT之前,此方法之后应该在视图的父级上调用requestLayout()和invalidate(),以强制父级使用新的子级排序重绘.
必须在视图的父级上调用这些方法.您在视图本身上调用它们.
这应该工作.
tvLevel.bringToFront(); tvLevel.getParent().requestLayout(); tvLevel.getParent().invalidate();
bringToFront()
为我工作android.support.design.widget.CoordinatorLayout
.我的环境:
Android Studio 1.5.1
设备:摩托罗拉与Android 4.1.2(API 16)
activity_main.xml中:
MainActivity.java:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = (TextView) findViewById(R.id.textView); textView.bringToFront(); }
以下是截图:
同 textView.bringToFront();
没有 textView.bringToFront();