Android/2012.04월 강좌
10일차 TabView
Bohemian life
2012. 5. 9. 15:37
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <!-- 예약어@android:id/tabhost --> <TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" > </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/tab1" android:layout_width="match_parent" android:layout_height="match_parent" > <AnalogClock android:layout_width="100dp" android:layout_height="100dp" /> </LinearLayout> <LinearLayout android:id="@+id/tab2" android:layout_width="match_parent" android:layout_height="match_parent" > <DigitalClock android:layout_width="100dp" android:layout_height="100dp" /> </LinearLayout> <LinearLayout android:id="@+id/tab3" android:layout_width="match_parent" android:layout_height="match_parent" > <Chronometer android:layout_width="100dp" android:layout_height="100dp" /> </LinearLayout> </FrameLayout> </LinearLayout> </TabHost> </LinearLayout>sub.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <RatingBar android:id="@+id/ratingBar1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ExpandableListView android:id="@+id/expandableListView1" android:layout_width="match_parent" android:layout_height="wrap_content" > </ExpandableListView> </LinearLayout>manifast.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.gusfree.tapview" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".TapViewActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="SubActivity"></activity> </application> </manifest>TapViewActivity.java
package com.gusfree.tapview; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.widget.AnalogClock; import android.widget.TabHost; public class TapViewActivity extends TabActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //@android:id/tabhost //탭위젯에다가 제목등을 셋팅하고, //각각의 탭위젯과 LinearLayout을 연결해주기 //1. TabHost를 불러오자 @android:id/tabhost //TabActivity 상속 받아서 가능한 메서드 TabHost tabHost = getTabHost(); TabHost.TabSpec spec1 =tabHost.newTabSpec("태그1"); TabHost.TabSpec spec2 =tabHost.newTabSpec("태그2"); TabHost.TabSpec spec3 =tabHost.newTabSpec("태그3"); TabHost.TabSpec spec4 =tabHost.newTabSpec("태그3"); spec1.setIndicator("첫번째 스펙"); spec2.setIndicator("",getResources().getDrawable(R.drawable.red)); spec3.setIndicator(new AnalogClock(this)); spec4.setIndicator("네번째"); spec1.setContent(R.id.tab1); spec2.setContent(R.id.tab2); spec3.setContent(R.id.tab3); Intent intent =new Intent(); intent.setClass(this,SubActivity.class); spec4.setContent(intent); tabHost.addTab(spec1); tabHost.addTab(spec2); tabHost.addTab(spec3); tabHost.addTab(spec4); } }SubActivity.java
package com.gusfree.tapview; import android.app.Activity; public class SubActivity extends Activity{ @Override protected void onStart() { super.onStart(); setContentView(R.layout.sub); } }