Gooday Note Scrap Source Android login
 
작성일 : 11-04-03 02:51
Tab Layout
 글쓴이 : 관리자
조회 : 3,934   추천 : 0   비추천 : 0  
   http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/Android/TabActiv… [1611]
   http://developer.android.com/resources/tutorials/views/hello-tabwidget… [7178]
따라하기 만큼 좋은 방법이 없는 것 같다. Tab 인터페이스 생성 예제.. Android 1.5 Version으로 테스트 했다. 시간되면 2.0 버전으로 테스트 해봐야지.

Layout

  • Layout 이름 : TabHost
<?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"> 
   <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
       <TabWidget 
           android:id="@android:id/tabs" 
           android:layout_width="fill_parent" 
           android:layout_height="wrap_content" /> 
       <FrameLayout 
           android:id="@android:id/tabcontent" 
           android:layout_width="fill_parent" 
           android:layout_height="fill_parent"> 
           <LinearLayout 
            android:orientation="vertical" 
            android:layout_width="fill_parent" 
               android:layout_height="fill_parent" 
            android:id="@+id/tabview1"> 
            <TextView 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:text="tabview1" /> 
               <Button 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:text="Just put something here" /> 
                /> 
           </LinearLayout> 
           <LinearLayout 
            android:orientation="horizontal" 
            android:layout_width="fill_parent" 
               android:layout_height="fill_parent" 
            android:id="@+id/tabview2"> 
            <TextView 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:text="tabview2" /> 
               <Button 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:text="A" /> 
                /> 
               <Button 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:text="B" /> 
                /> 
               <Button 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:text="C" /> 
                /> 
           </LinearLayout> 
           <TextView 
               android:id="@+id/tabview3" 
               android:layout_width="fill_parent" 
               android:layout_height="fill_parent" 
               android:text="tabview3" /> 
       </FrameLayout> 
   </LinearLayout> 
</TabHost> 
 

java Code

import android.app.TabActivity; 
import android.os.Bundle; 
import android.widget.TabHost; 
 
public class TestTab extends TabActivity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
        
        TabHost mTabHost = getTabHost(); 
        
        mTabHost.addTab(mTabHost.newTabSpec("tab_test1") 
          .setIndicator("탭 1") 
          .setContent(R.id.tabview1)); 
        mTabHost.addTab(mTabHost.newTabSpec("tab_test2") 
          .setIndicator("탭 2") 
          .setContent(R.id.tabview2)); 
        mTabHost.addTab(mTabHost.newTabSpec("tab_test3") 
          .setIndicator("탭 3") 
          .setContent(R.id.tabview3)); 
        
        mTabHost.setCurrentTab(0); 
    } 
}