일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- 아이폰 메모리 관리
- 텐서
- singular vector decomposition
- 태그를 입력해 주세요.
- Objective c
- 머신러닝 책
- retatin
- spectral decomposition
- CORS
- property 속성
- 딥러닝 책
- ios 메모리관리
- Property
- nonatomic
- 머신러닝
- OCRS
- matrix decomposition
- dot syntax
- ios 메모리
- 딥러닝 첫걸음
- 기계학습
- 딥러닝
- TENSOR
- 스펙트럼 분해
- Cross-origin resource sharing
- 안드로이드
- Machine Learning
- CORS c#
- objective-c
- 행렬 분해
- Today
- Total
One Step for A Little Progress
안드로이드 탭뷰(TabView) 만들기(TabActivity 상속한 방법) 본문
레이아웃 xml 파 일
<?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> <TabWidget android:id="@android:id/tabs" android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <FrameLayout android:id="@android:id/tabcontent" android:layout_above="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </RelativeLayout> </TabHost>
탭 호스트 > 탭 위젯 > 프레임 레이아웃 순으로 작성한다.
탭 액티비티를 사용할 경우에 탭호스트의 아이디는 "@android:id/tabhost"
탭위젯의 아이디는 "@android:id/tabs"
프레임 레이아웃의 아이디는 "@android:id/tabcontent"
이렇게 하지 않으면 탭액티비티를 통해서 탭을 사용할 수 없다.
이때 프레임 레이아웃에는 각 탭별로 들어갈 탭의 레이아웃이나 내용을 넣어주면된다.
또한 기본 옵션에서 탭의 위치는 위쪽이다. 아래쪽에 탭을 놓고싶다면, 위와같이
RelativeLayout으로 탭위젯과 프레임 레이아웃을 감싸 준 후
<TabWidget android:id="@android:id/tabs" android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <FrameLayout android:id="@android:id/tabcontent" android:layout_above="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
android:layout_above="@android:id/tabs"
이부분을 추가해주게 되면 아래쪽에 탭이 위치하게 된다.
Activity파일
먼저 AndroidManifest.xml파일에서 액티비티를 추가해준 후
이름을 정해주고, 상속받는 클래스는 TabActivity클래스로 정해준다.
TabHost mTabHost=getTabHost(); TabHost.TabSpec spec; Intent intent; intent=new Intent().setClass(this, MainActivity.class); spec=mTabHost.newTabSpec("main").setIndicator("Main").setContent(intent); mTabHost.addTab(spec); mTabHost.setCurrentTab(0);
위의 코드와 같이 탭호스트를 생성해주고, getTabHost() 메소드를 통해서 탭호스트를 가져온다.
그 다음 TabSpec을 생성하여, 탭스펙의 이름과, Indicator(탭에 표시될 이름), 그리고 탭에 표시될 내용인 콘텐트를 설정해준다.
그리고 탭호스트에 해당 스펙으로 탭을 추가해주고. 현재 탭의 인덱스를 설정해주면 탭이 생성이된다.
setContent내에는 위의 코드처럼 인텐트를 만들어 다른 액티비티로 넘어가게 할 수도 있고(탭은 그대로 표시된다)
xml파일에서 frameLayout내에 뷰를 추가시켜 뷰의 아이디를 통해 내용을 표시할수도 있다.
'Develop > Android' 카테고리의 다른 글
안드로이드 탭뷰(TabView) 탭에 액티비티 넣기(탭에 인텐트 넣기) (0) | 2012.03.30 |
---|---|
안드로이드 layout include하기 (0) | 2012.03.28 |
안드로이드 탭뷰(TabView) 탭 크기 조정 (0) | 2012.03.28 |
안드로이드 탭뷰(TabView) 만들기(Activity를 이용한 방법) (0) | 2012.03.28 |
안드로이드 타이틀바(Titlebar 없애기) (0) | 2012.03.25 |