• Android之TabHost重定义


    更多参考:http://www.360doc.com/content/12/0515/13/7857928_211171985.shtml

    效果图:




    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:id="@+id/linearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >
    
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >
            </TabWidget>
    
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
            </FrameLayout>
        </LinearLayout>
    
    </TabHost>


    TabHost的主文件:

    public class MainActivity extends TabActivity {
        String[] title = new String[]{"ni","wo","ta","we"};  
        View userTab,articeTab,feedTab,weTab;  
        View[] tabs = new View[]{userTab,articeTab,feedTab,weTab};  
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            TabHost tabHost = getTabHost();  
            tabHost.setup();   //Call setup() before adding tabs if loading TabHost using findViewById().   
              
            for(int i=0;i<tabs.length;i++){ 
                Intent intent = new Intent(this,AActivity.class);
                tabs[i] = (View) LayoutInflater.from(this).inflate(R.layout.tabmini, null);  
                ImageView text = (ImageView) tabs[i].findViewById(R.id.tab_label);             
                tabHost.addTab(tabHost.newTabSpec(title[i]).setIndicator(tabs[i]).setContent(intent)); 
                tabHost.setCurrentTab(1);
            }  
        }
    }

    TabHost里面的布局(tabmini.xml):

    <?xml version="1.0" encoding="utf-8"?>  
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
        android:layout_width="fill_parent"  
        android:layout_height="40dp"  
        android:paddingLeft="5dip"  
        android:paddingRight="5dip"  
        android:background="#ff0000">    
          
        <ImageView android:id="@+id/tab_label"    
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content"  
            android:layout_centerInParent="true"  
            android:gravity="center"  
            android:background="@drawable/btndown"
            />   
    </RelativeLayout>
  • 相关阅读:
    Dynamic Performance Tables not accessible Automatic Statistics Disabled for this session
    Log4Net使用指南
    .NET 邮件传送功能实现(smtp.qq.com)
    解决VS2008调试过程中无法启动程序或找不到元素
    20070115 18:38 动态显示用户输入的字数,文本框只能输入数字的代码
    SVN 错误;: Server sent unexpected return value (405 method not allowed)
    WdatePicker日历控件联动效果
    RockMelt – 社交浏览器
    AnkhSVN
    ASP.NET 把DataTable与Lis<T>转成json输出
  • 原文地址:https://www.cnblogs.com/lee0oo0/p/2937802.html
Copyright © 2020-2023  润新知