framelayouts를 사용하여 조각을 보관하는 경우 언급 한 다른 조각과 동일합니다. 단편 (레이아웃이 무엇이든간에)을 인스턴스화하고 다른 레이아웃 대신 프레임 레이아웃으로 바꾸십시오.
조각을 XML로 하드 코딩 한 경우 해당 결정을 수행 할 수 없습니다 (가능한 한).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frames"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/hline1"
android:layout_below="@id/horizontalline"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/leftpane"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight=".4" />
<TextView
android:id="@+id/verticalline"
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="@color/bar_background"
android:gravity="center_horizontal"
android:paddingLeft="5dip"
android:paddingRight="5dip" />
<FrameLayout
android:id="@+id/rightpane"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" >
</FrameLayout>
</LinearLayout>
main.xml에 그런 다음 당신은 FrameLayout이로 조각을 넣어 FrameLayout이 당신의 인스턴스화 조각의 이름에 대한 ID를 사용합니다. 당신은 내용을 변경하려는 경우
EventListFragment eventlist = new EventListFragment();
getFragmentManager().beginTransaction().replace(R.id.leftpane, eventlist).commit();
EventDetailFragment eventadd = new EventDetailFragment();
getFragmentManager().beginTransaction().replace(R.id.rightpane, eventadd).commit();
, 당신은 (다시 같은 일을 수행 할 수 있습니다 새로운/다른 조각과 오른쪽 창에서 조각을 대체 할 다음 그것과 관련된 자신의 다른 레이아웃입니다 그것) :
EventSuperDetailFragment eventsuper = new EventSuperDetailFragment();
getFragmentManager().beginTransaction().replace(R.id.rightpane, eventsuper).commit();
당신의 도움을 많이 주셔서 감사합니다! 단편 개념은 나에게 상당히 새로운 것이다. 몇 가지 간단한 예를 들어 설명해 주시겠습니까? –
내 대답을 업데이트했습니다. 올바른 방향으로 안내해 줄 수 있기를 바랍니다. 알려줘! – Barak
감사합니다 바락! 예, 효과가있었습니다. 또한 조각 내에서 조각을 만들 수 있는지 알고 싶었습니다. –