What’s difference between removeAllViews() and removeAllViewsInLayout()

As Scott Biggs points out, the difference is not a big one. The only difference is that removeAllViews() calls requestLayout() and invalidate() afterwards. The key to why this difference is here is to understand the naming of removeAllViewInLayout(). Confusingly, its meaning isn’t “remove all views within this view layout.”

If we look at the similar method, removeViewInLayout(), we can understand what it’s supposed to mean:

Removes a view during layout. This is useful if in your onLayout() method, you need to remove more views.

So removeAllViewsInLayout() actually means “remove all views, and we’re calling this method during a layout pass (i.e. onLayout())”. That’s why removeAllViewsInLayout() doesn’t call through to requestLayout(), as it’s assumed that you’re already currently inside a layout pass, so requesting another layout pass is unneeded.

If you use removeAllViewsInLayout(), then it’s your responsibility to ensure that you’re calling this during a layout pass, or to properly call requestLayout() and invalidate() as needed.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)