1

How to know when a view is actually visible on screen? View.getVisibility is not accurate enough for my case. It gets set to true before the view is completely rendered. Specifically, I'm using a textview.

2
  • What do you do with the information? I am thinking you could fire an event after the view is rendered.
    – dazza5000
    Commented Jan 20, 2018 at 1:19
  • I need to put the accessibility focus on it which doesn't work unless the view is physically visible on the screen. All the callbacks I tried get triggered before the actual rendering.
    – Son Nguyen
    Commented Jan 21, 2018 at 4:11

1 Answer 1

0

I think you need this:

OnGlobalLayoutListener ()

https://stackoverflow.com/questions/16189525/ongloballayoutlistener-deprecation-and-compatibility/16190337#16190337

3
  • Doesn't work.! I tried every callback. OnDraw and OnPredraw (callbacak of the viewtree, not the view itself) get called both before and after the view is visible, which is really hard to determine.
    – Son Nguyen
    Commented Jan 21, 2018 at 2:01
  • Are you sure that it is not you who modifies something (maybe its contents through an assignment or change its dimensions or those of its container) and then to unleash the ondraw () following the first? ... should not recall it if not layout changes take place involving it ... if you call it back then I do not know how to help you.
    – Bronz
    Commented Jan 21, 2018 at 2:42
  • I'm pretty sure I don't modify anything, except I give it the accessibility focus (feature to support users with vision impair). It's the title of an alertdialog. When the alert pops up, I need to put the focus on it with sendAccessibilityEvent, but this doesn't work unless the view is already rendered.
    – Son Nguyen
    Commented Jan 21, 2018 at 4:09

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