使用TabHost和FrameLayout实现导航
来源:互联网 发布:黑马程序员视频 编辑:程序博客网 时间:2024/05/15 17:12
android的官方Api上面已经明确标出TabActivitywas deprecated in API 13,被弃用.但是TabHost这个组件还是大有可为,是一个很好的UI框架.TabHost结合FrameLayout就可以实现导航
java代码:
MyTabHost
<span style="font-size:18px;">package com.example.tabhost;import android.annotation.SuppressLint;import android.app.Activity;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.widget.TabHost;import android.widget.TabHost.OnTabChangeListener;import android.widget.TabHost.TabSpec;import android.widget.TabWidget;public class MyTabHost extends Activity {private TabHost tabHost;private TabWidget tabWidget;private View guid_image1,guid_image2,guid_image3,guid_image4;@SuppressLint("InflateParams")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_tab_host);// 获取tabHost, tabHost是个容器组件tabHost = (TabHost)findViewById(R.id.tableH); // 类似于初始化过程,不调用无法获取到tabWiget,调用addTab需要tabwiget。TabActivity内部已经调用了tabHost.setup();guid_image1 = (View)LayoutInflater.from(this).inflate(R.layout.guide_image1, null);guid_image2 = (View)LayoutInflater.from(this).inflate(R.layout.guide_image2, null);TabSpec spec1 = tabHost.newTabSpec("tab1").setIndicator(guid_image1).setContent(R.id.content1);TabSpec spec2 = tabHost.newTabSpec("tab2").setIndicator(guid_image2).setContent(R.id.content2);tabHost.addTab(spec1);tabHost.addTab(spec2);tabWidget = tabHost.getTabWidget();// tabHost.getTabWidget(); 这一步很重要,没有上一步,必须这一步tabHost.setOnTabChangedListener(new OnTabChangeListener() {@Overridepublic void onTabChanged(String tabId) {// TODO Auto-generated method stub}});}}</span>
主布局文件:
activity_tab_host
<span style="font-size:18px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" ><TabHost android:id="@+id/tableH" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <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="0dp" android:layout_weight="1" //这个权重极重要~~ 不然显示不出相应tab的内容 > <TextView android:id="@+id/content1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="消息1" /> <TextView android:id="@+id/content2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="消息2" /> <span style="white-space: pre;"></span></FrameLayout> </LinearLayout></TabHost></LinearLayout></span>
布局文件1:
guide_image1
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center" > <TextView android:id="@+id/guide1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="~!!~!~!!~!~!" android:textSize="25sp" > </TextView></LinearLayout></span>
布局文件2:
guide_image2
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center" > <TextView android:id="@+id/guide2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="~!!~!~!!~!~!" android:textSize="25sp" > </TextView></LinearLayout></span><span style="font-size:24px;"></span>
0 0
- 使用TabHost和FrameLayout实现导航
- 使用TabHost+Fragment实现导航
- TabHost+TabWidget+FrameLayout实现底部菜单页面
- 选项卡TabHost、TabWidget和FrameLayout
- 使用 RadioGroup+TabHost 搭建框架实现 导航 切换
- 采用TabHost和RadioButton实现页面导航效果
- 底部tabhost研究三 (TabWidget ,FrameLayout 在TabHost内。TabWidget 和FrameLayout 平行的关系)
- TabHost实现底部导航示例
- 使用FrameLayout实现遮罩层
- 使用FrameLayout实现遮罩层
- RadioGroup+FrameLayout实现底部导航页面
- FragmentTabHost+FrameLayout实现底部导航栏
- FragmentTabHost+FrameLayout实现底部导航栏
- 使用TabHost和ViewPager实现页面切换
- tabhost,framelayout,tabwidget(一)
- 使用FrameLayout(帧布局) 和Timer实现动态图片
- 使用FrameLayout实现霓虹灯效果
- android RadioGroup+TabHost实现导航栏
- 如何进行 iOS 兼容性测试
- Sql Server数据库设计和高级查询
- sql
- Android系统设计中存在设计模式分析
- 安装并使用memcached
- 使用TabHost和FrameLayout实现导航
- linux 内核分析(转)
- 设计模式--简单工厂、工厂方法和抽象工厂
- 推荐广告系统—CTR在业务层面的意义
- 我的.Net学习之路六——快速的批量插入数据
- JAVA获取文件的创建日期
- hoj2651(二分查找)
- Mysql 5.x
- 黑马程序员——C语言(函数、数组、字符串、进制、内存分析)总结