在Android中移除View通??梢酝ㄟ^以下幾種方式實現(xiàn):
ViewGroup parentView = (ViewGroup) childView.getParent();
if (parentView != null) {
parentView.removeView(childView);
}
childView.setVisibility(View.GONE);
childView.setVisibility(View.INVISIBLE);
childView.animate().alpha(0f).setDuration(300).withEndAction(new Runnable() {
@Override
public void run() {
ViewGroup parentView = (ViewGroup) childView.getParent();
if (parentView != null) {
parentView.removeView(childView);
}
}
}).start();
以上是一些常見的移除View的方法,在實際開發(fā)中可以根據(jù)具體情況選擇合適的方法。