在做scrollview 滑动停靠的时候 需要addView 报错 其实在做viewpager的时候也遇到过类似的问题 具体报错如下:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first.
contaner.addView(view);
之前应该这样写:
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null) {
parent.removeAllViews();
}
contaner.addView(view);
就好了 另外注意:view.getParent()得到的并不是view 也就没有removeView() 方法