Android_TabHost用户界面之一_140930
来源:互联网 发布:matlab接口编程 编辑:程序博客网 时间:2024/05/16 11:40
TabHost 和 ListView 类似, 都是UI 界面设计的一种便携方式; 接下来记录一些个人的学习笔记
TabHost ,查阅了一些资料发现,有两种方式
1)继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.。只要定义具体Tab内容布局就可以了 (这在参考的链接中包含)
2)不用继承TabActivity,在布局文件中定义TabHost即可,但是 TabWidget的id必须是 @android:id/tabs,FrameLayout的id必须是@android:id/tabcontent。TabHost的id可以自定义.
个人比较喜欢第二种方法,因此用第二种方法。
//activity_main.xml
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" > </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/tab1" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="11111111" /> </LinearLayout> <LinearLayout android:id="@+id/tab2" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="22222222" /> </LinearLayout> <LinearLayout android:id="@+id/tab3" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="33333333" /> </LinearLayout> </FrameLayout> </LinearLayout></TabHost>注释:
TabWidget:未标题栏,其中定义了 @android:id/tabs数组,这些id可在MainActivity.java文件中设置显示的内容
FrameLayout: 内容栏,其中定义了 @android:id/content数组,这些 content与tabs 为一一对应的关系
//MainActivity.java文件
package com.yline.tabhost;import android.app.Activity;import android.os.Bundle;import android.widget.TabHost;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);TabHost tabHost = (TabHost) findViewById(R.id.tabhost); tabHost.setup();tabHost.addTab(tabHost.newTabSpec("界面1") .setIndicator("界面1", getResources().getDrawable(R.drawable.ic_launcher)) .setContent(R.id.tab1));tabHost.addTab(tabHost.newTabSpec("界面2") .setIndicator("界面2") .setContent(R.id.tab2));tabHost.addTab(tabHost.newTabSpec("界面3") .setIndicator("界面3") .setContent(R.id.tab3));}}
注释:
tabhost.setup : (提示内容的显示)
Call setup() before adding tabs if loading TabHost using findViewById(). However: You do not need to call setup() after getTabHost() inTabActivity
.
如果你是使用findViewByid的方法得到TabHost,请调用setup();(第二种方法,书写tabHost)
如果你是通过继承TabAvtivity方法使用getTabActivity方法,就不需要调用setup()。(第一种方法,书写tabHost)
Example:
mTabHost = (TabHost)findViewById(R.id.tabhost);mTabHost.setup();mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");
UI界面:
TabHost 代码链接:
http://pan.baidu.com/s/1bnlKiYF
借鉴资料链接:
http://zxl-ong.iteye.com/blog/744809
- Android_TabHost用户界面之一_140930
- Android_TabHost
- Android_TabHost
- 用户界面测试系列之一
- android用户界面之一
- android_TabHost设置点击事件newTapSpec_141001
- 使用ADF Faces 之一:开发用户界面(基于AJAX)
- 【用户界面:jQWidgets探索之路系列】之一:开篇简介
- 用户界面
- 用户界面
- 用户界面
- 用户界面
- 用户界面
- 【用户界面:android-Ultra-Pull-To-Refresh】之一:android-Ultra-Pull-To-Refresh开篇
- 用户界面规范
- 《 用户界面设计 》
- 用户界面设计
- 指南:用户界面
- 基于物联网操作系统HelloX的智慧家庭体系架构
- 观察者模式(C语言实现)
- Android4.4使用 webview控件报错nativeOnDrawfailed;clearing to background color
- Android五种数据传递方法汇总
- 关于新技术学习的10点建议
- Android_TabHost用户界面之一_140930
- 关于 delete 的解释
- UVa-674-Coin Change
- UML类图详解
- 黑马程序员--Java高级--网络编程学习1
- grep
- 水
- 【产品体验】说到音乐专属推荐,你曾听过豆瓣FM
- 算法分析--书的页码问题