美文网首页
异常:You must call removeView() on

异常:You must call removeView() on

作者: 楷桐 | 来源:发表于2017-07-24 01:11 被阅读34次

参考:http://www.jianshu.com/p/d43d0ac7e2f7

~RQ0_DUR__0STLDQS02_93S.png

view在上次已经是某个ParentView的child,然而现在又把它做为另外一个view的child,于是出现一个view有两个parent。所以就产生了这个错误。

解决办法1:

// 第二个参数parent不能为null
 LayoutInflater.from(getContext()).inflate(R.layout.layout_search, (ViewGroup) recyclerSearch.getParent(), false);

解决办法2:

虽然画的有点抽象.png

个人理解是,因为F已经被添加到ViewGroup A中了,不能再被添加到ViewGroup B中,直白点就是,一女不能侍二夫。。
想要把F添加到ViewGroup B中,就要ViewGroup A先把F移除掉,再添加到B中去

  View inflate = LayoutInflater.from(this).inflate(R.layout.baidu_map, null);
        tracing_mapView = (MapView) inflate.findViewById(R.id.tracing_mapView);
//以下是重点
        if (tracing_mapView != null) {
            ViewGroup parentViewGroup = (ViewGroup) tracing_mapView.getParent();
            if (parentViewGroup != null ) {
                parentViewGroup.removeView(tracing_mapView);
            }
        }

相关文章

网友评论

      本文标题:异常:You must call removeView() on

      本文链接:https://www.haomeiwen.com/subject/smevkxtx.html