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.
CodePudding user response:
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
CodePudding user response:
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;
}