2013년 9월 5일 목요일

android - place fragments into the tabs (provided by action bar)

0. tab 속으로 fragment layout 넣기
  • http://developer.android.com/guide/topics/ui/actionbar.html#Tabs를 참고하면 action bar에 tabs을 추가하는 방법이 나와 있는데, 이대로 예제를 따라가다가 각 탭에 UI를 집어 넣어 보면 control들이 탭 속에 들어오는게 아니라 전체 activity 화면 위에 위치하게 된다.
1. How?
  • 문서의 예제인데 FragmentTransaction.add() 메소드를 호출할 때 layout에  android.R.id.content 를 넣어 줘서 그렇다. 이 부분을 fragment를 담을 layout으로 지정하면 tab 속에 fragment가 들어간다. 예를 들어 아래와 같이 activity layout xml파일에 추가한 R.id.fragment_container를 넣어주면 된다.
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:layout_gravity="center">
    <LinearLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </LinearLayout>
</LinearLayout>

댓글 없음:

댓글 쓰기