检查某个视图是否被其他视图(不是窗口)完全隐藏了

时间:2019-01-30 08:47:46

标签: android view

我有两个视图A和B。视图B完全覆盖了视图A,这意味着视图B的边界矩形比视图A的边界矩形大。

我能给出的最好的例子是,我有一个固定的底部标签布局和一个带有多个线性布局的RecyclerView。滚动时,线性布局之一将位于底部标签的布局后面。

因此,如何以编程方式检查视图A是否被其他视图完全覆盖(其他视图可能不是预先知道的)

有没有可能的方法来识别这个?

更新: 我已经尝试过提及here的解决方案。但这并不能解决我的问题。就我而言,视图边界是完全匹配的,我希望哪个视图位于顶部。

2 个答案:

答案 0 :(得分:0)

使用以下方法将帮助您查找重叠的视图:-

private boolean isYourViewOverlapping(View firstView, View secondView) {
        int[] firstPosition = new int[2];
        int[] secondPosition = new int[2];

        firstView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        firstView.getLocationOnScreen(firstPosition);
        secondView.getLocationOnScreen(secondPosition);

        int r = firstView.getMeasuredWidth() + firstPosition[0];
        int l = secondPosition[0];
        return r >= l && (r != 0 && l != 0);
    }

答案 1 :(得分:0)

经过大量的努力,我找到了一种方法,可以通过以下方法来确定视图是否被其他视图重叠。

typedef struct adressIP { // la structure AdressIP
    int n1; int n2; int n3; int n4; }
ADRESSIP;

typedef struct machine{ // la structure Machine ,, represente un pc
    struct machine * suivant;
    const char nom;
    ADRESSIP *ip;
} MACHINE;

typedef struct reseau{ // la structure reseau comme une liste
    MACHINE * suivant;
    long long size;
    short vide; }
RESEAU;


MACHINE * create_machine(RESEAU *r){ // Creation d'une machine and erreur
    MACHINE *m = malloc(sizeof(MACHINE));
    if(m == NULL){
        printf("\nErreur");
        return NULL;
    }

    ADRESSIP * ip = malloc(sizeof(ADRESSIP));
    if(ip == NULL){
        printf("\nErreur");
        return NULL;
    }

    m->suivant = NULL;
    m->ip = ip; //erreur

    return m;
}