我想在动画过程中更改某些视图的z顺序
在4.1.2以上的Android上它可以正常工作,而在4.1.2以下的Android上,Z顺序不变,顶视图仍位于顶部。
这就是我正在尝试的。
myView.bringToFront();
((View)myView.getParent()).invalidate();
如何使其在较旧的设备上运行?
/**
* 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();
而且有效!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句