To move a view around I call setX, setY, and some other functions that set width and height and call either invalidate or requestLayout at the end of each of these functions. As a result invalidate and requestLayout gets called multiple times per user event. Does this trigger multiple layout/draws per user event?
Of course not.We can see code in ViewRootImpl
void invalidate() {
mDirty.set(0, 0, mWidth, mHeight);
if (!mWillDrawSoon) {
scheduleTraversals();
}
}
invalidate set dirty area, and call scheduleTraversals,it will call doTraversal.
void doTraversal() {
if (mTraversalScheduled) {
mTraversalScheduled = false;
mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier);
if (mProfile) {
Debug.startMethodTracing("ViewAncestor");
}
performTraversals();
if (mProfile) {
Debug.stopMethodTracing();
mProfile = false;
}
}
}
we can see mTraversalScheduled flag in the code,if we are scheduleding travel, an invalidate events triggerd,mTraversalScheduled is false in doTraversal,so the method will return directly. So NOT every invalidate events called performTravel,NOT every invalidate events called redraw
Yes, it does. Everytime you call invalidate, the view itself will redraw!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With