查看前面的视图不起作用 [英] View bring to front doesnt work

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

问题描述

我想在动画过程中更改某些视图的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();

成功了!

I want to change z order of some views during animation

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.

This is what i am trying.

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();

and it worked!

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

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