我想在动画期间更改某些视图的z顺序
在4.1.2以上的机器人上工作得很好,在4.1.2以下的机器人上,Z顺序没有变化,顶视图仍然在顶部.
这就是我想要的.
myView.bringToFront(); ((View)myView.getParent()).invalidate();
如何使它在旧设备上运行?
我希望这对某人有用。以上解决方案均不适合我。为什么?因为我想成为叶状体的视图的标高比其他视图小。因此,无论高高低低,总是能看到最前面的景色。
我尝试了所有这些.RelativeLayout应该在Button的顶部,但它只是不想服从.
最后,我通过添加android:elevation="2dp"
到RelativeLayout来解决它.
高程值仅用于API级别21及更高级别.在我的情况下,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); } }
根据这一点,我只是错过了这条线
((View)myView.getParent()).requestLayout();
它工作了!