Android的Tab控件(二)
来源:互联网 发布:软件试用总结报告 编辑:程序博客网 时间:2024/06/02 04:06
在上一篇Android的Tab控件(一)中,各个tabPage都由独立的Activity来实现。然而TabHost还有另外一种实现方法。接下来就来讲解,在实现的时候我附加了一个功能,就是当tab页太多的时候,默认情况下tab页会缩小挤在一起,我们给TabWidget加一个HorizontalScrollView,就可以实现TabWidget的左右滚动。先来看效果图;
Activity代码:
public class ScrollTabActivity extends Activity{Intent intent;TabHost.TabSpec tabSpec;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.scrolltab);Resources res=getResources();// 获取TabHost对象TabHost tabHost = (TabHost) findViewById(R.id.tabhost);// 如果没有继承TabActivity时,通过该种方法加载启动tabHosttabHost.setup();tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("第一个标签",getResources().getDrawable(R.drawable.image)).setContent(R.id.view1));tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("第二个标签").setContent(R.id.view2));tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("第三个标签").setContent(R.id.view3));tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator("第四个标签",getResources().getDrawable(R.drawable.image)).setContent(R.id.view4));tabHost.addTab(tabHost.newTabSpec("tab5").setIndicator("第五个标签").setContent(R.id.view5));tabHost.addTab(tabHost.newTabSpec("tab6").setIndicator("第六个标签").setContent(R.id.view6));}}布局文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/hometabs"android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- TabHost必须包含一个 TabWidget和一个FrameLayout--> <TabHost android:id="@+id/tabhost" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" > <LinearLayoutandroid:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="none"> <!-- TabWidget的id属性必须为 @android:id/tabs--> <TabWidget android:id="@android:id/tabs" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> </TabWidget></HorizontalScrollView> <!-- FrameLayout的id属性必须为 @android:id/tabcontent--> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/view1" android:text="diyige " android:layout_width="fill_parent" android:layout_height="fill_parent"/> <TableLayout android:id="@+id/view2" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TableRow android:id="@+id/tableRow2" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" android:text="密码" /> <EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableRow> <TableRow android:id="@+id/tableRow3" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮2" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮1" /> </TableRow> </TableLayout> <TextView android:id="@+id/view3" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <TextView android:id="@+id/view4" android:text="diyige " android:layout_width="fill_parent" android:layout_height="fill_parent"/> <TextView android:id="@+id/view5" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <TextView android:id="@+id/view6" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </FrameLayout> </LinearLayout> </TabHost> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hha"/></LinearLayout>
另外,如果想让标签页显示在最下面,只需要交换TabWidget和FrameLayout 的位置就行了。
- Android的Tab控件(二)
- Android的Tab控件(一)
- Android Tab 控件的使用
- android Tab控件的tabhost、tabwiget
- Android Design新控件之TabLaout(二),仿微信实现App底部Tab布局
- Android Design新控件之TabLaout(二),仿微信实现App底部Tab布局
- Android tab切换控件
- Android Tab的实现方法(二) FragmentTab
- (转)vc的tab控件使用
- 漂亮的TAB控件
- tab控件的用法
- Tab控件的使用
- Tab控件的使用
- Tab控件的使用
- |tab控件的使用|
- tab控件的问题
- Android的GridView控件(二)
- Android的GridView控件 (二)
- export关键字
- hash表--d-left-hashing
- 1.2项目规范
- retain和copy还有assign的区别,以及引用计数
- 5.把hbm转化为DDL有两种方式:总结
- Android的Tab控件(二)
- webkit学习笔记1---webcore简单执行流程
- 我的第三个Android应用软件——《新概念3》
- Android定制属于你自己的导航栏
- 设计包含min函数的栈
- 大型网站架构演变和知识体系
- 数理逻辑:谓词演算(目录)
- poj (3468)线段树lazy操作
- XCLNetSearch1.0(ASP.NET通用查询服务器控件)