2013-10-18 1 views
37

큰 화면을위한 레이아웃을 만들고 있는데, 왼쪽과 오른쪽의 두 가지 파트로 구성되어 있습니다. 그것을하기 위해 나는 2 개의 단편을 사용하는 것이 올바른 선택이라고 생각했습니다.Android : 언제/왜 조각 대신 FrameLayout을 사용해야합니까?

그런 다음 마스터/세부 흐름을 사용하여 탐색 예제를 살펴 보았습니다. 그것은 오른쪽에 네비게이션이 있고 왼쪽에는 상세보기 인 2 칸 레이아웃이 있습니다. 내가 볼 것으로 예상 한 것과 다른

그러나 예

은 상세보기를 다음 대신 직접 Fragment의하는 Fragment을 보유하고 FrameLayout있다.

레이아웃 XML이 (예를 들어)과 같습니다

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="16dp" 
    android:layout_marginRight="16dp" 
    android:baselineAligned="false" 
    android:divider="?android:attr/dividerHorizontal" 
    android:orientation="horizontal" 
    android:showDividers="middle" 
    tools:context=".WorkStationListActivity" > 

    <fragment 
     android:id="@+id/workstation_list" 
     android:name="de.tuhh.ipmt.ialp.history.WorkStationListFragment" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     tools:layout="@android:layout/list_content" /> 

    <FrameLayout 
     android:id="@+id/workstation_detail_container" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="3" /> 

</LinearLayout> 

내 질문을 지금하십시오 FrameLayout 대신 상세 뷰에 대한 Fragment 자체 사용되는 이유는 무엇입니까? 그 이유는 무엇입니까? 나는 그것을 사용해야합니까?

답변

36

표시되는 FragmentFragmentTransactionreplace() 방법으로 대체되므로 세부 컨테이너가 FrameLayout입니다.

replace()의 첫 번째 인수는 조각이 대체 될 컨테이너의 ID입니다. 이 예제의 FrameLayout이 Fragment로 대체 된 경우 WorkStationListFragment과 Fragment가 현재 표시된 모든 세부 정보가 새 Fragment로 대체됩니다. Fragment를 FrameLayout에 캡슐화하면 세부 사항 만 바꿀 수 있습니다.

+0

사실 도움이되었습니다. 필자의 경우, 조각을 대체 할 필요가 없으므로 이제'FrameLayout'을 그대로두고'Fragment'를 직접 사용할 수 있습니다. – Terry

2

사용자 인터페이스의 변경 내용에 응답 할 필요가없는 경우 <fragment>을 사용하여 활동에 조각을 추가하십시오. 그렇지 않은 경우 <FrameLayout> 프레임 레이아웃은 화면의 영역을 차단하는 데 사용되는보기 그룹 유형입니다.

관련 문제