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.

Son Nguyen
  • 1,124
  • 2
  • 10
  • 24
  • What do you do with the information? I am thinking you could fire an event after the view is rendered. – dazza5000 Jan 20 '18 at 01: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 Jan 21 '18 at 04:11

1 Answers1

0

I think you need this:

OnGlobalLayoutListener ()

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

Bronz
  • 217
  • 3
  • 7
  • 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 Jan 21 '18 at 02: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 Jan 21 '18 at 02: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 Jan 21 '18 at 04:09