본문 바로가기
프로그래밍 놀이터/안드로이드, Java

[Android/안드로이드] Tab Activity 의 모든 것.

by 돼지왕 왕돼지 2012. 2. 18.
반응형


안녕하세요. 돼지왕 왕돼지입니다.
오늘은 Tab Activity 의 모든 것. 이라는 주제로 이야기해보겠습니다.


TabHost 를 이용한 탭 구현.

 
<APIs>

TabHost getTabHost()
 
void addTab(TabHost.TabSpec tabSpec)
TabHost.TabSpec TabHost.newTabSpec (String tag)
 
TabHost.TabSpec setIndicator (CharSequence label [, Drawable icon])
TabHost.TabSpec setContent(int viewId)
TabHost.TabSpec setContent (TabHost.TabContentFactory  contentFactory)
TabHost.TabSpec setContent (Intent intent)

 

<example>

<layout xml>
<FrameLayout>
  <LinearLayout id="opt_general">
     <Views>
  </LinearLayout>
 
  <LinearLayout id="opt_compiler">
     <Views>
  </LinearLayout>
 
  <TextView id="opt_linker"/>
</FrameLayout>
 
<java>
public class TabTest extends TabActivity{
   TabHost mTab = getTabHost();
   LayoutInflater inflater = LayoutInflater.from(this);
   inflater.inflate(R.layout.tabtest, mTab.getTabContentView(), true);
 
   mTab.addTab(mTab.newTabSpec("tag").setIndicator("일반").setContent(R.id.opt_general));
   mTab.addTab(mTab.newTabSpec("tag").setIndicator("컴파일러").setContent(R.id.opt_compiler));
   mTab.addTab(mTab.newTabSpec("tag").setIndicator("링커").setContent(R.id.opt_linker);
}

 


  
 

TabContentFactory 를 이용한 Tab 구현

 
View TabHost.TabContentFactory.createTabContent (String tag) 

<example 1>

public class TabTest2 extends TabActivity{
   TabFactory factory = new TabFactory(this);
   TabHost tabHost = getTabHost();
 
   Drawable icon = getResources().getDrawable(R.drawable.icon);
   tabHost.addTab(tabHost.newTabSpec("General").setIndicator("일반",icon).setContent( factory ));
   tabHost.addTab(tabHost.newTabSpec("Compiler").setIndicator("컴파일러",icon).setContent( factory ));
   tabHost.addTab(tabHost.newTabSpec("Linker").setIndicator("링커",icon).setContent( factory )); 
}
 
class TabFactory implements TabHost.TabContentFactory{
   Context mCon;
   TabFactory(Context context){
      mCon = context;
   }
 
   public View createTabContent (String tag){
      TextView text = new TextView(mCon);
      text.setText("Tab View of " + tag);
      return text;
   }
}

 
 
 <example 2>

puiblic class TabTest2 extends TabActivity implements TabHost.TabContentFactory{
   ...
   public View createTabContent (String tag){
   }
}

 

<example 3>

tabHost.addTab(tabHost.newTabSpec("tag").setIndicator("Curve").setContent( new Intent(this, .class) ));

 
 

 
 
 

페이지 겹치기로 탭 구현하기.

 
 <example>

<layout xml>
<LinearLayout>
   <FrameLayout>
      <LinearLayout id = "opt_general">
           <Views>
      </LienarLayout>
     
     <LinearLayout id ="opt_compiler">
            <Views>
     </LinearLayout>
    
      <View>
   </FrameLayout>
 
   <RadioGroup
       android:orientation="horizontal"
       android:layout_width="fill_parent"
       android:layout_height="65px"
       android:gravity="center_vertical"
       android:background="#808080"
       android:checkedButton="@+id/btn1">
 
         <RadioButton
             android:id="@+id/btn1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_weight="1"
             android:text="일반"/>
         <RadioButton
             android:id="@+id/btn2"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_weight="1"
             android:text="컴파일러"/>
         <RadioButton
             android:id="@+id/btn3"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_weight="1"
             android:text="링커"/>
    </RadioGroup>
</LinearLayout>
 
<java>
View mPage1, mPage2, mPage3;
 
void ChangePage(int page){
   mPage1.setVisibility(View.INVISIBLE);
   mPage2.setVisibility(View.INVISIBLE);
   mPage3.setVisibility(View.INVISIBLE);
 
   switch (page){
   case 1:
       mPage1.setVisibility(View.VISIBLE);
       break;
    ...
   }
}

 
 
로그인 없이 추천 가능합니다. 손가락 꾸욱~

반응형

댓글