问题描述
对试图组件快速的左右滑动过程,发现某一张图片没加载出来,偶现crash
问题分析
view在上次已经是某个ParentView的child,然而现在又把它做为另外一个view的child,于是出现一个view有两个parent。所以就产生了这个错误。
问题解决
方案1:宣称主权
// 第二个参数parent不能为null
 LayoutInflater.from(getContext()).inflate(R.layout.layout_search, (ViewGroup) recyclerSearch.getParent(), false);
方案2:先移除,解绑与父view的关系,再重复添加
 
 个人理解是,因为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);
            }
        }

















![[LLM-Agents]浅析Agent工具使用框架:MM-ReAct](https://img-blog.csdnimg.cn/direct/06db47bc1ee64db68f750330142c4cd1.jpeg#pic_center)

