How to know when a view is actually displayed
I have a Gallery that开发者_StackOverflow displays multiple scrollable frames, each containing a complex layout. One of these layout elements is a gauge-like custom view that should animate whenever it gets displayed - not just created. So if I scroll to the layout containing this view once, then go back, then scroll there again - it should do its animation and the user should see it.
I didn't find an appropriate callback for that. What I've already tried is overriding:
onDraw
onLayout
onAttachedToWindow
onDisplayHint
onVisibilityChanged
Some of them are not called at all, and some are called only when the Gallery re-initializes the view - not when it is actually displayed.
Thank ahead!
You could try overriding getView
on your Gallery's adapter:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
/* trigger your animation on this view */
return view;
}
There isn't an explicit contract for when getView
is called, but it should be called when the view in question appears on the screen.
精彩评论