android开发实例-TabHost的使用
2012-09-25 17:18
435 查看
布局文件要先添加<TabWidget/>(如红体所示);
一个个的小标题就是tab(清音、浊音、拗音);
盛放Tab的容器就是TabHost;
下面的framelayout布局中就可以插入tab了(如蓝体所示);
tab下面可以另外插入控件,我这里插入的是listview(如绿体所示);
在java文件中定义的类为了方便使用getTabHost()函数可以继承TabActivity类;
一个个的小标题就是tab(清音、浊音、拗音);
盛放Tab的容器就是TabHost;
下面的framelayout布局中就可以插入tab了(如蓝体所示);
tab下面可以另外插入控件,我这里插入的是listview(如绿体所示);
<RelativeLayout 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="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" > <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" > </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="5dp"> <LinearLayout android:id="@+id/tab1" android:layout_width="match_parent" android:layout_height="match_parent" > <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" > </ListView> </LinearLayout> <LinearLayout android:id="@+id/tab2" android:layout_width="match_parent" android:layout_height="match_parent" > <ListView android:id="@+id/listView2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" > </ListView> </LinearLayout> <LinearLayout android:id="@+id/tab3" android:layout_width="match_parent" android:layout_height="match_parent" > <ListView android:id="@+id/listView3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" > </ListView> </LinearLayout> </FrameLayout> </LinearLayout> </TabHost> </RelativeLayout>
在java文件中定义的类为了方便使用getTabHost()函数可以继承TabActivity类;
package com.wxp.activity0922; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.Window; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TabHost; import android.support.v4.app.NavUtils; import android.widget.*; public class Activity1 extends TabActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_activity1); TabHost tabHost=getTabHost(); Resources res=getResources(); TabHost.TabSpec spec; Intent intent; intent=new Intent().setClass(this,PingJia.class); spec=tabHost.newTabSpec("***").setIndicator("***", res.getDrawable(R.drawable.qy)).setContent(intent); tabHost.addTab(spec); intent=new Intent().setClass(this,ZhuoYin.class); spec=tabHost.newTabSpec("***").setIndicator("***", res.getDrawable(R.drawable.zy)).setContent(intent); tabHost.addTab(spec); intent=new Intent().setClass(this,AoYin.class); spec=tabHost.newTabSpec("***").setIndicator("***", res.getDrawable(R.drawable.ay)).setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(0); } }
相关文章推荐
- 实例讲解Android应用开发中TabHost的使用要点
- Android开发存储方式详解之SQLite使用实例
- Android 开发实例 Base64的使用
- Android 开发中使用Linux Shell实例详解
- Android开发之TabHost控件的使用
- Android使用SurfaceView进行涂鸦的开发实例
- Android开发之关于使用PopWindow点击外部不消失的解决实例
- C#开发Android的tabhost使用+侧拉抽屉
- Android开发之TabHost组件实例
- Android开发之道(10)Handler本质简析与使用实例
- 实例讲解Android app开发中ListView的基本使用及优化
- Android App开发中使用RecyclerView实现Gallery画廊的实例
- Android webview控件(一) 使用webview开发浏览器实例
- android开发之TabHost分页标签使用案例(带滑动效果)
- android开发经典实例系列----TabHost、Gallery
- Android开发实践(三)WebView(网络视图)使用实例
- Android-使用Android studio 进行NDK-JNI开发实例(一)
- Android GZip的使用-开发中网络请求的压缩实例详解
- Android开发学习笔记——TabHost实例
- Android-使用C++实现调用本地方法返回字符串显示在界面上/NDK-JNI开发实例(八)