android中的tab,其实很简单,几个步骤

1 首先是一个布局文件,一般是framelayout中有多个linarlayout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:id="@+id/widget_layout_Blue"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText android:id="@+id/widget34" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="EditText"
android:textSize="18sp">
</EditText>
<Button android:id="@+id/widget30" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Button">
</Button>
</LinearLayout>
<LinearLayout android:id="@+id/widget_layout_red"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >
<AnalogClock android:id="@+id/widget36"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</AnalogClock>
</LinearLayout>
<LinearLayout android:id="@+id/widget_layout_green"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<RadioGroup android:id="@+id/widget43"
android:layout_width="166px" android:layout_height="98px"
android:orientation="vertical">
<RadioButton android:id="@+id/widget44"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="RadioButton">
</RadioButton>
<RadioButton android:id="@+id/widget45"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="RadioButton">
</RadioButton>
</RadioGroup>
</LinearLayout>
</FrameLayout>


2 实际代码:
public class MyTab extends TabActivity implements OnTabChangeListener {

private TabHost myTabhost;

}
注意这里是继承TabActivity了,之后的TabHost用来容纳每一个标签页,还可以包含任何类型的视图.

protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

myTabhost=this.getTabHost();
myTabhost.addTab(myTabhost.newTabSpec("One").setIndicator("A",getResources().getDrawable(R.drawable.gimp)).setContent(R.id.widget_layout_Blue));
.........

myTabhost.setCurrentTab(0);


这里,addTab()用来给TabHost上添加一个页;
newTabSpec方法的参数指定该TAB项的ID值得,当在不同的tab切换时,TABHOST会发送不同的ontabchange消息,消息的参数就是该id值.
setIndicator用于指定标签页上显示的内容,还可以加图标.
setcontent()用来指定该tab页对应的视图.

对事件的响应:
  public void onTabChanged(String tagString) {
// TODO Auto-generated method stub
if (tagString.equals("One")) {
myMenuSettingTag = 1;
Toast.makeText(getApplicationContext(), "tabid="+tagString,Toast.LENGTH_LONG).show();

}

更多相关文章

  1. android中的tab小结
  2. android 布局xml中 android:fitsSystemWindows="true"的作用
  3. view属性大全
  4. Android进阶——Android视图工作机制之measure、layout、draw
  5. android最佳实践(二)
  6. cocos2dx打包Android出现“未指定Android目标平台版本”问题
  7. Mono for Android(安卓)实现高效的导航
  8. android中view的一些属性
  9. 高级组件之网格视图

随机推荐

  1. Android(安卓)View MarqueeView 跑马灯效
  2. Android(安卓)adb shell 命令大全
  3. [置顶] Android(安卓)5.1 open data flow
  4. Android高德地图自定义放大缩小控件
  5. 【专题】Android(安卓)启动流程相关
  6. Android的SDK与ADT不匹配问题
  7. SQLite语法与Android数据库操作
  8. android EditText inputType说明
  9. Android(安卓)map
  10. Android(安卓)UI(1)Getting Started - Fi