/**
* Removes a view during layout. This is useful if in your onLayout() method,
* you need to remove more views.
*
* <p><strong>Note:</strong> do not invoke this method from
* {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)},
* {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p>
*
* @param view the view to remove from the group
*/
public void removeViewInLayout(View view) {
removeViewInternal(view);
}
/**
* {@inheritDoc}
*
* <p><strong>Note:</strong> do not invoke this method from
* {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)},
* {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p>
*/
public void removeView(View view) {
removeViewInternal(view);
requestLayout();
invalidate(true);
}
同样的还有 removeAllViewsInLayout() 和 removeAllViews(),
简单test了一下, 在removeAllViewsInLayout()之后, requestLayout() 并不能让view刷新,必须 invalidate(), 而这就是 removeAllViews()办的事情,
如果只invalidate(), 不requestLayout()的话, view的尺寸不会因为子view的remove()而变化(view是wrap_content的)
public void removeAllViews() {
removeAllViewsInLayout();
requestLayout();
invalidate(true);
}