android - 如何获取 View /布局的 z-index ?或者如何知道它是否在前面?

标签 android android-layout

如何获取 View /布局的 z-index ?或者如何知道它是否在前面? 我专门需要它用于RelativeLayout

我正在寻找类似 view.getIndex() 或 view.isOnFront()

最佳答案

试试这个

RelativeLayout re=(RelativeLayout) findViewById(R.id.MyRelative);
    int[] zIndexTab=new int[re.getChildCount()];
    for (int i = 0; i < re.getChildCount(); i++) {
        zIndexTab[i]=re.getChildAt(i).getId(); // zIndexTab[0] will have the Id of the first child in this Layout etc..
        // So the first index corresponding to the first view.
        // The smaller View index will be under the biggest View Index
        // for example my first View is a button it's index is 0 , the second view is a spinner it's index is 1
        // so the spinner will be on the front of the button etc..
    }

关于android - 如何获取 View /布局的 z-index ?或者如何知道它是否在前面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9928913/

相关文章:

android - Gradle 错误 : Could not find method android()

java - 无法从 SocketChannel 读取数据

android - 可绘制 2 种纯色

android-layout - Android Studio 3.1 中的 GridLayout 名称或如何在 3.1 中使用它?

android - 从右到左增加 Android 按钮的宽度

Android RelativeLayout,隐藏 View 并将 View 向上推

android - 带有 Phonegap 的 Android 混合应用程序上的 Iframe 视频

android - Android 版 Google Map SDK 中标记周围的 map 不可点击

android - 保持应用程序在后台运行

android - 我可以在其中动态创建带有 RadioButtons 的 RadioGroup(没有 xml)吗?