0

Say I have View A and View B as sibling views in my Android activity. View B hides View A (for example, view B has a black background hiding view A) They both have the exact same dimensions filling up the entire visible screen.

How can I check programmatically during runtime if view A is visible to the user? I've tried isVisibleToUser, isVisible, isFocus, isShown etc which all don't work, since view A is set as visible, but due to the drawing order, is hidden by view B.

1
  • If you check for visibility of view B, and if it is true, it should be fair to say view A is hidden in your case, otherwise if view B's visibility is false, check if view A is visible, and if it is true, view A is visible, you can use this as a logic Commented Feb 23, 2022 at 16:55

2 Answers 2

0

ok listen bro for example you have two views v1,v2; this is a code to check if v1 is visible or not

if (v1.getVisibility()==View.VISIBLE)
{
 // if v1 is visible
}
else
{
// if v1 not visible
}

same check for v2

2
  • both return true.. any other ideas?
    – And
    Commented Feb 23, 2022 at 18:40
  • dear first you set visibility gone in xml and then set visible one of them in onCreate Commented Feb 23, 2022 at 18:42
0

Try the following:

 switch (view.getVisibility()){
        case View.VISIBLE:
            //The View is visible to the user.
            break;
        case View.INVISIBLE:
            //The view is not visible to the user but is still on the screen.
            break;
        case View.GONE:
            //The view is not visible to the user and is no longer on the screen.
            break;
    }
    
2
  • both return true.. any other ideas?
    – And
    Commented Feb 23, 2022 at 18:40
  • i guess you can make it such that the view you want to be hidden always has a lower elevation that the view that is hiding it.
    – Brandon
    Commented Feb 23, 2022 at 18:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.