• android:TabHost总结


    Tabs:标签、选项

    在android布局中,Tabs具有良好的用户体验

    Tabs in the action bar make it easy to explore and switch between different views or functional aspects of your app, or to browse categorized data sets.

    然后总结一下TabHost

    public class

    TabHost

    extends FrameLayout
    implements ViewTreeObserver.OnTouchModeChangeListener
    java.lang.Object
       ↳ android.view.View
         ↳ android.view.ViewGroup
           ↳ android.widget.FrameLayout
             ↳ android.widget.TabHost

    继承自FrameLayout,并实现了触摸监听接口

    Class Overview

     分页式窗口视图的一种容器,包含两种子元素:标签(TabWidget)和对应的内容页(FrameLayout)。TabHost将这些元素统一起来进行控制。

    TabHost的两种实现方法:

    第一种:继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost。

            myTabhost=this.getTabHost();  
            //get Tabhost  
            LayoutInflater.from(this).inflate(R.layout.main, myTabhost.getTabContentView(), true);  
            myTabhost.setBackgroundColor(Color.argb(150, 22, 70, 150));  
              
            myTabhost  
                    .addTab(myTabhost.newTabSpec("One")// make a new Tab  
                            // set the Title and Icon  
                            .setIndicator("A")
                            .setContent(R.id.widget_layout_Blue));  
            // set the layout  
    

    第二种:不继承TabActivity,在布局文件中定义TabHost

      TabWidget的id必须是@android:id/tabs

      FrameLayout的id必须是@android:id/tabcontent

      TabHost的id可以自定义

    <?xml version="1.0" encoding="utf-8"?>  
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
        android:id="@+id/hometabs"  
        android:orientation="vertical"  
        android:layout_width="fill_parent"    
        android:layout_height="fill_parent">   
        <TabHost android:id="@+id/tabhost"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content">  
            <LinearLayout  
                android:orientation="vertical"  
                android:layout_width="fill_parent"  
                android:layout_height="fill_parent">  
                  
                <TabWidget android:id="@android:id/tabs"   
                  android:orientation="horizontal"  
                  android:layout_width="wrap_content"  
                  android:layout_height="wrap_content">  
                </TabWidget>  
               
                 <FrameLayout android:id="@android:id/tabcontent"  
                      android:layout_width="wrap_content"  
                      android:layout_height="wrap_content">  
                        <TextView android:id="@+id/view1"  
                            android:layout_width="fill_parent"  
                            android:layout_height="fill_parent"/>  
                        <TextView android:id="@+id/view2"  
                            android:layout_width="fill_parent"  
                            android:layout_height="fill_parent"/>  
                        <TextView android:id="@+id/view3"  
                            android:layout_width="fill_parent"  
                            android:layout_height="fill_parent"/>  
                 </FrameLayout>  
               
             </LinearLayout>  
        </TabHost>  
    </LinearLayout>  
    

    实现代码:

    protected void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.hometabs);  
              
            TabHost tabHost = (TabHost) findViewById(R.id.tabhost);  
            tabHost.setup();  
            TabWidget tabWidget = tabHost.getTabWidget();  
              
            tabHost.addTab(tabHost.newTabSpec("tab1")  
                    .setIndicator("tab1", getResources().getDrawable(R.drawable.mumule))  
                    .setContent(R.id.view1));  
              
            tabHost.addTab(tabHost.newTabSpec("tab3")  
                    .setIndicator("tab3")  
                    .setContent(R.id.view3));  
              
            tabHost.addTab(tabHost.newTabSpec("tab2")  
                    .setIndicator("tab2")  
                    .setContent(R.id.view2));    
            
        }  
    

      

     

  • 相关阅读:
    hdu 1272
    BZOJ_3685_普通van Emde Boas树_权值线段树
    BZOJ_3831_[Poi2014]Little Bird_单调队列优化DP
    BZOJ_3252_攻略_线段树+dfs序
    BZOJ_4653_[Noi2016]区间_线段树+离散化+双指针
    BZOJ_3210_花神的浇花集会_切比雪夫距离
    BZOJ_2124_等差子序列_线段树+Hash
    BZOJ_2212_[Poi2011]Tree Rotations_线段树合并
    BZOJ_1826_[JSOI2010]缓存交换 _线段树+贪心
    BZOJ_4325_NOIP2015 斗地主_DFS
  • 原文地址:https://www.cnblogs.com/skiz/p/2734321.html
Copyright © 2020-2023  润新知