zoukankan      html  css  js  c++  java
  • Android:TabHost导航栏

    通常情况下,我们都需要用到TabHost做一个导航功能。

    这也就需要我们更好的使用TabHost进行各项界面之间的跳转。

    首要我们新建一个XML:

    <TabHost 
        android:id="@android:id/tabhost" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/first_bg"
        xmlns:android="http://schemas.android.com/apk/res/android">
        
        <LinearLayout 
            android:orientation="vertical"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent">
    
            <FrameLayout 
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent" 
                android:layout_height="0.0dip"
                android:layout_weight="2.0" />
                
            <TabWidget 
                android:id="@android:id/tabs" 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:padding="2dip"
                android:background="@drawable/down_bar"
                android:layout_weight="0.0"/>
                
        </LinearLayout>
        
    </TabHost>

    MainActivity 我们进行如下操作:

    public class MainActivity extends TabActivity{
        private TabHost mTabHost;
        private LayoutInflater mLayoutInflater;
        
        private Class mTabClassArray[] = {
            ClassicMoiveActivity.class,
            HotMovieActivity.class,
            ExpectMovieActivity.class
        };
        
        private int mImageViewArray[] = {
            R.drawable.sutra,
            R.drawable.hot,
            R.drawable.expect
        };
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            initWidget();
        }
        
        
        private void initWidget() {
            mTabHost = getTabHost();
            mLayoutInflater = LayoutInflater.from(this);
    
            for (int i = 0; i < mTabClassArray.length; i++) {
                TabSpec tabSpec = mTabHost.newTabSpec("").setIndicator(getTabItemView(i)).setContent(getTabItemIntent(i));
                mTabHost.addTab(tabSpec);
                mTabHost.getTabWidget().getChildAt(i)
                        .setBackgroundResource(R.drawable.selector_tab_background);
            }
    
        }
    
        private View getTabItemView(int index) {
            View view = mLayoutInflater.inflate(R.layout.tab_item_view, null);
            
            ImageView imageView = (ImageView) view.findViewById(R.id.imageview);
            if (imageView != null) {
                imageView.setImageResource(mImageViewArray[index]);
            }
            return view;
        }
    
        private Intent getTabItemIntent(int index) {
            Intent intent = new Intent(this, mTabClassArray[index]);
            return intent;
        }
        
    }

     

  • 相关阅读:
    安装OpenCV:OpenCV 3.0、OpenCV 2.4.8、OpenCV 2.4.9 +VS 开发环境配置
    各种编程语言的深度学习库整理
    十个开源深度学习框架
    深度学习框架的评估与比较
    Caffe 深度学习框架上手教程
    机器视觉开源代码集合
    人工智能的妙用:谷歌公布图像字幕技术
    谷歌推出最新图像识别工具Google Cloud Vision API
    机器学习常见算法分类汇总
    神经网络的分类及其应用
  • 原文地址:https://www.cnblogs.com/gongcb/p/2494491.html
Copyright © 2011-2022 走看看