实现采用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用户界面-组件Widget-画廊视图Gallery
  2. android xml 解析 修改
  3. Android(安卓)常用代码集合
  4. android NDK学习篇3之two-libs——使用(多个)静态库生成动态库
  5. 通过Titanium Studio为Android(安卓)APK签名
  6. Android(安卓)最终image文件的来源
  7. 手动编译源码,打造自己的增量更新。
  8. mybatisplus的坑 insert标签insert into select无参数问题的解决
  9. NPM 和webpack 的基础使用

随机推荐

  1. android 6 sdk/ndk下载地址
  2. android 跳转到应用通知设置界面(Android
  3. Android多媒体开发(5)————利用Android(
  4. Android(安卓)中三种使用线程的方法
  5. Android(安卓)原生获取地理位置
  6. ANDROID NDK文档系列--(一)Android(安卓)ND
  7. android之单选框
  8. Android触控事件
  9. 1、What Makes an Android(安卓)Applicat
  10. Android(安卓)问题(一)