如何在不调用BringToFront() 的情况下将视图置于前面? [英] How to bring a view to front without calling bringToFront()?

查看:36
本文介绍了如何在不调用BringToFront() 的情况下将视图置于前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 中显然有一个 错误,它破坏了<代码>View.bringToFront.

There is apparently a bug in Android which breaks View.bringToFront.

如果我在 GridView 中安排了 View,并且想通过调用 becomeToFront() 将 View 放在最前面,它可能会移动到 GridView 中的右下角位置.

If I have Views arranged in a GridView and want to bring a View to front by calling bringToFront(), it may get moved to the bottom right position in the GridView.

那里发生了一些阴暗的事情,所以我不能使用 combineToFront().当我不调用它时,一切正常.但是视图重叠 - 如果我使用缩放动画来放大视图,它会被底部和右侧的视图部分遮挡.

Something shady is going on there, so I can't use bringToFront(). When I don't call it, everything works fine. But the Views overlap - if I use scale animation to scale up a View, it's partially obscured by the Views to the bottom and to the right.

我已经查看了 combineToFront 的源代码,它调用了 parent.bringChildToFront(...)

I've checked out bringToFront's source and it calls parent.bringChildToFront(...)

就是这个方法

public void bringChildToFront(View child) {
     int index = indexOfChild(child);
      if (index >= 0) {
          removeFromArray(index);
          addInArray(child, mChildrenCount);
          child.mParent = this;
      }
  }

它显然从自身中删除了视图!毫不留情! ViewGroup 是不是太笨了,以至于它不能以任何其他方式来管理 Z-indexes 来控制周围?很明显,当 GridView 移除它的孩子然后再次添加它时,它会被放置在 Grid 的末尾!

it apparently removes the View from itself! Without mercy! Is a ViewGroup so dumb that it can't manage Z-indexes in any other way that shuffling controls around? Obviously when GridView removes its child and then adds it back again, it gets placed at the end of the Grid!

我可以做些什么来在其他视图之上显示视图而不诉诸某些黑客攻击?我想到的一件事是在 GridView 上方创建另一个视图,该视图似乎位于我试图带来的 ToFront() 上方,但我不喜欢这个解决方案.

Is there anything I can do to show a View on top of others without resorting to some hacking? One thing that comes to my mind is to create another View above the GridView, which will appear to be above the one I'm trying to bringToFront(), but I don't like this solution.

推荐答案

显然我错过了 GridView 中的 android:clipChildren="false" 属性.它解决了我的问题.

apparently I missed the android:clipChildren="false" property in GridView. It solves my problem.

这篇关于如何在不调用BringToFront() 的情况下将视图置于前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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