달력

0

« 2025/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

'FRAGMENT'에 해당되는 글 1

  1. 2013.02.19 [Android] 화면분할 - Fragment 1
2013. 2. 19. 23:39

[Android] 화면분할 - Fragment 카테고리 없음2013. 2. 19. 23:39

<Fragment>


Android UI 개념이 매우 부족한 가운데, fragment 라는 놈을 봤다. 


화면(activity)의 일부분을 조각(fragment)이라고 하고 

1. 하나의 화면(activity)을 여러 조각(fragment)으로 구성하기 위해

2. 동일 조각(fragment)을 여러 화면(activity)에서 사용하기 위해 

fragment를 사용한다. 


과거 tabactivity 또는 group activity 가 비슷한 기능을 했다고 하는데 뭔지 모르니깐 패쓰..


또다른 용도 중 하나는 좁은 핸드폰 화면에서 개발한 어플을 

큰 화면을 가지는 태블릿으로 포팅할 때, 기존 소스들을 재활용 하기 위한 목적도 있다고 한다. 


자세한 설명은 다른 블로그들을 참조하고, 

정확한 설명을 위해서는 맨 아랫줄 안드본진을 참고하자. (단, 영어라는 거...)


http://croute.me/486 - KOR 

http://sd0720.blogspot.kr/2012/07/fragment.html -  KOR

http://developer.android.com/guide/components/fragments.html - ENU


 


난 하위 메뉴 항목들을 프레그먼트로 만들어 보기로 한다. 


<하위 메뉴 layout>

만들고 싶은 메뉴들로 layout을 구성한다. 우선 버튼이 두개 있는 화면을 구성해 보자. 

프레그먼트 부분을 구분하기 위해 background 를 검은색으로 한다.


bottom_fragment.xml

<RelativeLayout 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:background="#000000" >


    <Button

        android:id="@+id/button1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentLeft="true"

        android:layout_alignParentTop="true"

        android:text="Button" />


    <Button

        android:id="@+id/button2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentTop="true"

        android:layout_toRightOf="@+id/button1"

        android:text="Button" />


</RelativeLayout>




<메인 Activity>

특이사항 없음


 MainActivity.java

 public class MainActivity extends Activity {

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

    }




<하위 메뉴 fragment>

메인 Activity의 subclass 로 만들어도 되지만, 일단은 class 분리함.


MenuBottomFragment.java

 public class MenuBottomFragment extends Fragment {

    @Override

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        return inflater.inflate(R.layout.fragment_bottom, container, false);

    }

}




<메인 Layout>

메인 레이아웃에 프레그먼트를 포함시킨다. 


activity_main.xml

<RelativeLayout 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"

    tools:context=".MainActivity" >


    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_centerHorizontal="true"

        android:layout_centerVertical="true"

        android:text="@string/hello_world" />


    <fragment

        android:id="@+id/fragment_one"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_alignParentBottom="true"

        class="co.kr.jjyoung.simul.BottomMenuFragment" />

    

</RelativeLayout>





<결과화면>









:
Posted by 피카프