3 回答
TA贡献1831条经验 获得超10个赞
private void replaceView(View oldV,View newV){
ViewGroup par = (ViewGroup)oldV.getParent();
if(par == null){return;}
int i1 = par.indexOfChild(oldV);
par.removeViewAt(i1);
par.addView(newV,i1);
}
TA贡献1804条经验 获得超7个赞
在我的情况下,它适用于oldSensor和newSnsor-oldView和newView:
private void replaceSensors(View oldSensor, View newSensor) {
ViewGroup parent = (ViewGroup) oldSensor.getParent();
if (parent == null) {
return;
}
int indexOldSensor = parent.indexOfChild(oldSensor);
int indexNewSensor = parent.indexOfChild(newSensor);
parent.removeView(oldSensor);
parent.addView(oldSensor, indexNewSensor);
parent.removeView(newSensor);
parent.addView(newSensor, indexOldSensor);
}
- 3 回答
- 0 关注
- 327 浏览
添加回答
举报