实现采用TabHost组件。
1、XML布局文件:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout
android:gravity="bottom"
android:layout_weight="1"
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
<TabWidget
android:layout_weight="0"
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

</LinearLayout>
</TabHost>
注意<FrameLayout>标签和<TabWidget>标签的顺序。
android:layout_weight的设置使位置靠下,否则默认是在上面的。
2、activity文件


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maintabs);
// Resource object to get Drawables
Resources res = getResources();
tabHost = getTabHost();
// Resusable TabSpec for each tab
TabHost.TabSpec spec;
// Reusable Intent for each tab
Intent intent;


// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this,HomeTab.class);


// Initialize a TabSpec for each tab and add it to the TabHost
String str_tabhome=res.getString(R.string.tab_home);
spec = tabHost.newTabSpec(str_tabhome).setIndicator(str_tabhome,res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);

String str_tab02=res.getString(R.string.tab02);
spec = tabHost.newTabSpec(str_tab02).setIndicator(str_tab02,res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);


tabHost.setCurrentTab(2);

}

3、效果如下:

更多相关文章

  1. Android(安卓)APK文件安装过程小结
  2. android布局layout中的一些属性
  3. Android(安卓)开关机动画
  4. 【Android应用开发】Android(安卓)Studio 简介 (Android(安卓)St
  5. Android图片堆叠效果实现
  6. 学习Android中的Adapter
  7. Mac系统cocos2dx + android 开发环境配置
  8. mybatisplus的坑 insert标签insert into select无参数问题的解决
  9. NPM 和webpack 的基础使用

随机推荐

  1. mysql查询语句中用户变量的使用代码解析
  2. 详解MySQL数据类型DECIMAL(N,M)中N和M分
  3. MySQL数据类型中DECIMAL的用法实例详解
  4. MySQL如何查看元数据锁阻塞在哪里
  5. JDBC连接mysql处理中文时乱码解决办法详
  6. linux/mac安装mysql忘记密码的解决办法
  7. MySQL操作之JSON数据类型操作详解
  8. Windows下Mysql启动报1067的解决方法
  9. MySQL分区字段列有必要再单独建索引吗?
  10. Ubuntu下MySQL安装及配置远程登录教程