이 같은 FrameLayout이 포함되도록 활동의 XML 레이아웃을 변경해야합니다
<!--Other XML layout elements, view-groups, views etc...; other stuff-->
<FrameLayout
android:id="@+id/id_1"
android:layout_width="@dimen/fl_width"
android:layout_height="@dimen/fl_height">
</FrameLayout>
우리가 지금하고 싶은; Activity의 XML 레이아웃에있는 FrameLayout을 Fragment의 레이아웃 파일 중 하나의 레이아웃으로 추가 한 것을 대체 할 수 있습니다. 당신의 작업 파일에 지금
,
- 는
- 가 fragmentManagers 들어 BeginTransaction() 메소드를 통해하여 FragmentTransaction 인스턴스를 수행하여, FragmentManger 객체를 인스턴스화합니다.
/*1)*/ FragmentManager fragmentManager = getSupportFragmentManager();
/*2)*/ FragmentTransaction ft = fragmentManager.beginTransaction();
그리고 이러한 변화
ft.replace(R.id.id_1, new YourFragment());
ft.commit();
인수 YourFragment()는 당신의 조각 중 하나의 인스턴스를 삽입 할 필요하게, 이것은 대체됩니다 YourFragments()의 FrameLayout의 현재 레이아웃. 우리는 마침내 fragmentTransaction을 커밋합니다.
당신이 간단 FrameLayout이 표시되면 새로운 조각 트랜잭션을 시작하고 위와 같이 새로운 조각으로 프레임 레이아웃을 교체 조각을 교체합니다.