Reputation: 569
I want to know if its possible to know if a view has been drawn on the screen.
I am not interested in setting a listener and waiting for it, as I already know how to do that. I am looking for a call, to get a true/false on if the view is currently on the screen.
I dont believe I can simply check the visibility as that is a preset variable, regardless of its state, though I could be wrong.
If the view is not draw, I will set a ViewTreeObserver and wait for it, but that is only neccessary if the view has not yet been drawn.
Upvotes: 0
Views: 822
Reputation: 466
if you just want to observe one view, try to create a custom view and override the draw()
and set a flag in it like:
public DemoView extends TextView {
private boolean mHasDrawn;
// ...
@override
public void draw(Canvas canvas) {
super.draw(canvas);
mHasDrawn = true;
}
}
then you can check the mHasDrawn
to ensure the view has been drawn.
However, I think setting a listener is better than this.
Upvotes: 0
Reputation: 831
since getVisibility() returns a predefined property and u don't want to set a listener; i think the only option is View.isShown(). i hope this helps.
Upvotes: 1