zoukankan      html  css  js  c++  java
  • 冲刺!

    昨天:用fragment做了一个标签栏

    困难:界面布局混乱

    今天:重新开始做了一个新的标签栏,换了一种方法。

    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <LinearLayout
            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" />
    
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
    
                <TextView
                    android:id="@+id/tab3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Tab3页面"
                    android:textSize="40dp" />
    
                <TextView
                    android:id="@+id/tab4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Tab4页面"
                    android:textSize="40dp" />
    
                <TextView
                    android:id="@+id/tab5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Tab5页面"
                    android:textSize="40dp" />
    
            </FrameLayout>
        </LinearLayout>
    
    </TabHost>
    tab.xml
    package com.example.zbytexttwo;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.widget.TabHost;
    
    public class TabActivity extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.tab);
    
            // 步骤1:获得TabHost的对象,并进行初始化setup()
            TabHost tabs = (TabHost) findViewById(R.id.tabhost);
            tabs.setup();
    
            //步骤2:获得TabHost.TabSpec增加tab的一页,通过setContent()增加内容,通过setIndicator增加页的标签
    
            LayoutInflater.from(this).inflate(R.layout.activity_main_jm, tabs.getTabContentView());
            tabs.addTab(tabs.newTabSpec("tag1").setIndicator("主界面").setContent(R.id.tab01));
    
            LayoutInflater.from(this).inflate(R.layout.activity_jin_qi, tabs.getTabContentView());
            tabs.addTab(tabs.newTabSpec("tag2").setIndicator("近期消费").setContent(R.id.tab02));
    
            /*增加第三个Tab */
            TabHost.TabSpec spec = tabs.newTabSpec("Tag3");
            spec.setContent(R.id.tab3);//单击Tab要显示的内容
            /* 显示Tab3内容*/
            spec.setIndicator("添加账单");
            tabs.addTab(spec);
    
            /*增加第4个Tab */
            spec = tabs.newTabSpec("Tag4");
            spec.setContent(R.id.tab4);//单击Tab要显示的内容
            /* 显示Tab4内容*/
            spec.setIndicator("修改账单");
            tabs.addTab(spec);
    
            /*增加第5个Tab */
            spec = tabs.newTabSpec("Tag5");
            spec.setContent(R.id.tab5);//单击Tab要显示的内容
            /* 显示Tab5内容*/
            spec.setIndicator("预期消费");
            tabs.addTab(spec);
    
    
    
            /* 步骤3:可通过setCurrentTab(index)指定显示的页,从0开始计算*/
            tabs.setCurrentTab(0);
        }
    }
    TabActivity
  • 相关阅读:
    [LeetCode] 19. Remove Nth Node From End of List 移除链表倒数第N个节点
    [LeetCode] 27. Remove Element 移除元素
    [LeetCode] 240. Search a 2D Matrix II 搜索一个二维矩阵 II
    [LeetCode] 74. Search a 2D Matrix 搜索一个二维矩阵
    [LeetCode] 452. Minimum Number of Arrows to Burst Balloons 最少箭数爆气球
    [LeetCode] 312. Burst Balloons 爆气球
    [LeetCode] 257. Binary Tree Paths 二叉树路径
    [LeetCode] 24. Swap Nodes in Pairs 成对交换节点
    [LeetCode] 680. Valid Palindrome II 验证回文字符串 II
    [LeetCode] 234. Palindrome Linked List 回文链表
  • 原文地址:https://www.cnblogs.com/vvxvv/p/12756149.html
Copyright © 2011-2022 走看看