사실 blackbelt에 대한
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.mylayout, null);
LinearLayout layoutCopy = (LinearLayout)view.findViewById(R.id.myLinearLayout);
체크 예를 들어
, 그건 내가 그것을 해결하지만, 새로운 레이아웃에 복사 레이아웃을 추가 할 때 난 여전히 오류가 있었는지 꽤 많이 있습니다. 이유는 내가 복사하고 싶었던 레이아웃에 여전히 부모가 있었기 때문입니다. 다음은 완전한 해결책입니다 (layoutRoot는 res/layout에있는 xml 레이아웃이고 myLinearLayout은 layoutRoot 파일의 LinearLayout입니다.) layoutToPlaceCopiedLayout은 복사 된 레이아웃을 넣을 레이아웃의 LinearLayout입니다.
LinearLayout newLayout = (LinearLayout)findViewById(R.id.layoutToPlaceCopiedLayout)
LayoutInflater inflater = LayoutInflater.from(this);
LinearLayout layoutRootCopy = (LinearLayout)inflatefrom(R.layout.layoutRoot);
LinearLayout layoutCopy = (LinearLayout)layoutRootCopy.findViewById(R.id.myLinearLayout);
ViewGroup parent = (ViewGroup)layoutCopy.getParent();
int index = parent.indexOfChild(layoutCopy);
parent.removeView(layoutCopy);
newLayout.addView(layoutCopy, index);