视图带到前面不起作用 [英] View bring to front doesnt work

查看:17
本文介绍了视图带到前面不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在动画期间更改某些视图的 z 顺序

I want to change z order of some views during animation

在 4.1.2 以上的 Android 上它工作得很好,而在 4.1.2 以下的 Android 上,Z 顺序不会改变,顶视图仍然在顶部.

On Androids above 4.1.2 it works just fine, and on androids below 4.1.2 the Z order doesnt change, the top view remains on top.

这就是我正在尝试的.

myView.bringToFront();
((View)myView.getParent()).invalidate();

如何让它在旧设备上运行?

How to make it work on older devices ?

推荐答案

   /**
     * 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 I was simply missing the line

((View)myView.getParent()).requestLayout();

它奏效了!

这篇关于视图带到前面不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆