Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does View.setVisibility(View.VISIBLE) forces the view to redraw even if it's already visible?

I'm trying to figure out the optimization for my custom view. I'm wondering if the calling to View.setVisibility(View.VISIBLE) forces the Android framework to update the view visibility (<- forcing the view to redraw) even if the view is already visible.

like image 956
Seraphim's Avatar asked Oct 18 '25 14:10

Seraphim's


1 Answers

No, it doesn't.

Take a look at setVisibility():

public void setVisibility(int visibility) {
    setFlags(visibility, VISIBILITY_MASK);
    if (mBGDrawable != null) mBGDrawable.setVisible(visibility == VISIBLE, false);
}

It simply calls setFlags(), which immediately returns if nothing has changed:

....
int changed = mViewFlags ^ old;
if (changed == 0) {
    return;
}

Even if it(somehow) got past there, it then checks for the individual flags changing, and only updates if one of them is different than it was.

like image 96
Geobits Avatar answered Oct 20 '25 04:10

Geobits



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!