android学习之-TabHost
来源:互联网 发布:五轴联动加工中心编程 编辑:程序博客网 时间:2024/05/16 04:41
TabHost的创建有两种方式:
1.使用android系统自带的。
2.自定义TabHost
------------------------------------------
1.系统自带:
main.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"> <TabWidget android:id="@android:id/tabs" android:layout_marginLeft="10dp" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" /> </LinearLayout></TabHost>
注意事项:上面的id要包括:id="@android:id/tabhost";:id="@android:id/tabs";id="@android:id/tabcontent"
activity:
创建一个类继承TabActivity
public class SettingActivity extends TabActivity{
setContentView(R.layout.main);
Resources res = getResources(); TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent; //1.设置 intent = new Intent(this,RegistActivity.class); spec = tabHost.newTabSpec("artists").setIndicator("", res.getDrawable(R.drawable.regist)) .setContent(intent); tabHost.addTab(spec); //2.选择 intent = new Intent(this,SelectActivity.class); spec = tabHost.newTabSpec("artists").setIndicator("", res.getDrawable(R.drawable.select)) .setContent(intent); tabHost.addTab(spec); //3.联系 intent = new Intent(this,ContactActivity.class); spec = tabHost.newTabSpec("artists").setIndicator("", res.getDrawable(R.drawable.contact)) .setContent(intent); tabHost.addTab(spec);
}
2.自定义TabHost
1.main.xm
<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/main_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"> <TabWidget android:id="@android:id/tabs" android:layout_marginLeft="10dp" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" /></LinearLayout></TabHost>
注意事项:
使用到的两个id是系统的
class文件:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_tabhost); tabHost=(TabHost)findViewById(R.id.TabHost01); tabHost.setup();
tabHost.addTab(tabHost.newTabSpec("tab1").setContent(R.id.LinearLayout1).setIndicator("aa")); tabHost.addTab(tabHost.newTabSpec("tab2").setContent(R.id.LinearLayout2).setIndicator("bb"));
tabHost.setCurrentTab(0); }
--------------------------------------------------------------
自己定义图片之间的一些参数:
//设置高度和padding int childCount = tabHost.getTabWidget().getChildCount(); for(int i = 0;i<childCount;i++) { tabHost.getTabWidget().getChildAt(i).setPadding(0, 0, 0, 0); tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50; }
- android学习之-TabHost
- Android学习之TabHost
- Android学习笔记之TabHost
- Android学习之 UI--Tabhost
- android学习笔记之四TabHost布局
- android学习笔记之四TabHost布局
- Android UI学习之TabHost常用技巧
- Android TabHost学习笔记
- android:tabHost学习记录
- android学习--TabHost
- android中tabhost学习
- Android开发之TabHost
- Android之TabHost
- android之TabHost
- android 之 TabHost
- android控件之TabHost
- Android之TabHost布局
- Android控件之TabHost
- 让情绪动能助沟通
- 移动开发入门必看——iOS 开发入门书籍推荐
- C++常见错误
- SSH整合之分页实现
- 建设“中国特色的团队”是当务之急
- android学习之-TabHost
- UML视图总结
- Drools 的叩门
- 13周任务:Fibnacci序列(迭代)
- Hadoop全分布模式安装和测试
- 领导转型:衡量团队的五个标准
- Lillian Shao用十年经验解读中国“公有云”落地为什么这么难?
- IIS常见问题及解答以及故障分析
- Detect network cable plugged or unplugged