zoukankan      html  css  js  c++  java
  • Android选项卡TabHost功能和用法

    1、布局文件

    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@android:id/tabhost"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.helloword.TabActivity" >
    
        <LinearLayout 
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
                
                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                </FrameLayout>
                
        </LinearLayout>
    
    </TabHost>

    tab1.xml 

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tab1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="左边 tab"/>
    
    </LinearLayout>

    tab2.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tab2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        
        <TextView
             android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:text="right tab"/>
    
    </LinearLayout>

    2、Activity 

    package com.example.helloword;
    
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.widget.TabHost;
    
    public class TabActivity extends Activity  implements View.OnClickListener{
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_tab);
            
            TabHost tabHost = findViewById(android.R.id.tabhost);
            tabHost.setup();
            
            LayoutInflater inflater = LayoutInflater.from(this);
            
            inflater.inflate(R.layout.tab1, tabHost.getTabContentView());
            inflater.inflate(R.layout.tab2, tabHost.getTabContentView());
            
            tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("left").setContent(R.id.tab1));
            
            tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("right").setContent(R.id.tab2));
            
            
        }
    
        @Override
        public void onPointerCaptureChanged(boolean hasCapture) {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            
        }
    
    }
  • 相关阅读:
    英语语法最终珍藏版笔记-16定语从句
    U3D-页游-检测机制-webplayer-调试方法
    Unity UGUI 的RectTransform参数的设置
    游戏贴图的基本知识
    游戏贴图与模型基本规范
    【游戏模型】游戏超写实贴图制作技巧
    灯光下角度不同会出现中间的片没有光照
    Unity3d中SendMessage 用法
    C# Hashtable赋值给另一个Hashtable时
    InvalidOperationException: out of sync
  • 原文地址:https://www.cnblogs.com/zoro-zero/p/11558118.html
Copyright © 2011-2022 走看看