13

My research brought me to dead-end.

There is an activity, which obviously have views in it.

There multiple ways to check if view is visible to user in context of is view on screen, or is it out of screen bounds.

But here is another situation: there is a relative layout and one view intentionally overlaps another, or there is a pop-up window in activity.

Methods, which are used to check if view visible or not (including getLocationOnScreen, getLocalVisibleRect, getHitRect, getDrawingRect), returning values, as if the view is visible on screen, despite the fact, that it is being overlapped with another, so I cannot check if view is visible to user.

Is there anyway to check that?

cheshie
  • 421
  • 1
  • 6
  • 18
  • Why do you need to this, exactly? Since we're talking multiple windows on top of each other, there isn't a way to do it in the framework. You can implement the check for overlapping views in the same window by walking the tree but it's not part of the framework. – Delyan Oct 09 '13 at 10:17
  • What is window in Android, btw? Is it the activity? So there isn't any way in Android framework to check if view is visible to end-user, which means that view is not out of bounds of screen and is not overlapped. – cheshie Oct 10 '13 at 19:41
  • An `Activity` has a `Window` and so does a `Dialog`. The windows are managed by the `WindowManager` system service and you have a limited interface to work with them (it's mostly decor views, panels, and UI features like the action bar, though you do have some lower-level control, too). It should be possible to write something that works across all your currently visible windows but I believe there's no way to do it out of the box. – Delyan Oct 10 '13 at 19:52
  • @cheshie Did you manage to find any solution? – Nishant Shah Nov 22 '13 at 04:47
  • 1
    @Sorry Boss, no actually. this task is freezed right now and i'm developing other features on the project. however, be sure, that as soon as i have any solution, i will post it. thanks for the interest. – cheshie Nov 23 '13 at 15:29

2 Answers2

-3

You can use view.isShown() method, this method return view visible state is result true view visible.

nurisezgin
  • 1,530
  • 12
  • 19
  • 8
    I don't know who +1'ed this answer but this is completely wrong. If you have been more careful, then you could read in my question, that the point is: is there any way to check that view is visible to user. I knew about View#isShown method. It just checks if View#getVisibility == Visible or not and it's not my case. – cheshie Oct 10 '13 at 19:43
  • 3
    What did you say? Carefully determine your thread's title. If semeone gave +1, has found what it is looking for. – nurisezgin Oct 11 '13 at 04:57
-5

You can try this

  if (myView.getVisibility() == View.VISIBLE) {
  // Its visible
  } else {
  // Either gone or invisible
  }

Hope it helps.

RussVirtuoso
  • 900
  • 1
  • 9
  • 20
  • 19
    No It can't be accepted answer, as in the question it is clearly mention that @cheshie wants to know if the view is actually in front of the user. There can be cases that view in hidden behind some other view and in that case myView.getVisibility() == View.VISIBLE still return true. – Gem Dec 07 '15 at 07:37
  • 1
    haha your answer is correct I don't know why you not have points :D –  Mar 14 '16 at 10:41