- 浏览: 294715 次
- 性别:
- 来自: 上海
最新评论
-
再_见孙悟空:
写的不错
Dialog -
a549262189:
支持下,正好在学习这块的内容!
Android Gesture Detector -
dcsff:
受教了
LayoutInflater -
庆_啊:
真厉害。
LayoutInflater -
ghj234:
学习了,哈哈
LayoutInflater
1. 最简单的TabHost,Tab来自于layout下的元素 (只从1个Layout中取数据)
(1)效果图
(2)代码
1)tab_demo.xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/tab_demo_tv1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="tab_demo_tv1" /> <TextView android:id="@+id/tab_demo_tv2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="tab_demo_tv2" /> <TextView android:id="@+id/tab_demo_tv3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="tab_demo_tv3" /> </FrameLayout>
2)TabDemo.java
public class TabDemo extends TabActivity { private TabHost tabHost; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tabHost = getTabHost(); LayoutInflater.from(this).inflate(R.layout.tab_demo, tabHost.getTabContentView(), true); tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Tab1", null).setContent(R.id.tab_demo_tv1)); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Tab2", null).setContent(R.id.tab_demo_tv2)); tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Tab3", null).setContent(R.id.tab_demo_tv3)); setContentView(tabHost); } }
2. TabHost绑定动态View(从2个Layout中取数据)
(1)效果图
(2)代码
1)tab_map.xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab_map_id" > </FrameLayout>
2)tab_hs.xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab_hs_id" > <TextView android:id="@+id/tab_hs_tv" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </FrameLayout>
3)MapView.java
public class MapView extends View { public MapView(Context context) { super(context); } protected void onDraw(Canvas canvas) { Paint p = new Paint(); canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.icon), 0, 0, p); } }
4)TabDemo.java
public class TabDemo extends TabActivity { private TabHost tabHost; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tabHost = getTabHost(); createTabSpec_map(); createTabSpec_hs(); setContentView(tabHost); } private void createTabSpec_map() { LayoutInflater inflater_tab1 = LayoutInflater.from(this); inflater_tab1.inflate(R.layout.tab_map, tabHost.getTabContentView()); /* * R.layout.tab_demo已被LayoutInflater注册,所以这个可以通过findViewById获得其对象 */ FrameLayout frameLayout = (FrameLayout) findViewById(R.id.tab_map_id); MapView mv = new MapView(this); frameLayout.addView(mv); TabHost.TabSpec tabSpec_map = tabHost.newTabSpec("map view"); tabSpec_map.setIndicator("map view", null); tabSpec_map.setContent(R.id.tab_map_id); // 动态绑定基于图片的View(通过一个Layout绑定) tabHost.addTab(tabSpec_map); } private void createTabSpec_hs() { LayoutInflater inflater_tab2 = LayoutInflater.from(this); inflater_tab2.inflate(R.layout.tab_hs, tabHost.getTabContentView()); TabHost.TabSpec tabSpec_hs = tabHost.newTabSpec("hs view"); tabSpec_hs.setIndicator("hs view"); tabSpec_hs.setContent(R.id.tab_hs_id); // 绑定一个新的Layout tabHost.addTab(tabSpec_hs); /* * 这个绑定View的操作必须要重新使用一个新方法来完成,因为Tab的生成是在onCreate()中完成的,onCreate()只被调用一次, * 但是数据更新操作是需要反复进行的,如果反复调用createTabSpec_hs()则会生成多个tab页,这是我们不希望的,所以单独把 * updata分离出来,数据更新时单独调用此方法就可以了。 */ updateTabSpec_hs(); } private void updateTabSpec_hs() { TextView tv = (TextView) findViewById(R.id.tab_hs_tv); tv.setText("This is tab2"); } }
3.
发表评论
-
如果在Eclipse中debug
2010-05-02 14:15 0最基本的操作是: 1, 首先在一个java文件中设断点,然后 ... -
How to download sourcecode of android with cygwin
2010-04-14 16:07 5083cygwin是一个在windows平台 ... -
TelephoneManager
2010-03-08 16:04 01. protected void onCreate(Bun ... -
eclipse c
2010-03-07 21:05 0Eclipse 除 了可以开发Java之外,还支持了许 ... -
android sdk安装
2010-02-02 23:37 34501.下载:http://developer.android.c ... -
google map my demo
2010-02-02 23:36 3164<uses-library android:name=& ... -
Toast
2010-02-02 23:35 14241. (1) public class ToastActi ... -
如何在MapView上画图
2010-02-02 23:34 1561http://ophone8.com/thread-4340- ... -
Service
2010-02-02 23:33 31141. Service生命周期 (1)Servic ... -
Notification
2010-02-02 23:33 18851. Notification构造器的参数 分别为: ... -
导航相关概念
2010-02-02 23:32 16731. Google Map的定位 (1)Goog ... -
PendingIntent和Intent
2010-02-02 23:28 9493Notification n = new Notificati ... -
Broadcast调用Service做的一个定时器
2010-02-02 23:28 36731. public class AlarmActivity ... -
Broadcast Receiver
2010-02-02 23:27 8659Broadcast Receiver用于接收并处理广播通知(b ... -
LayoutInflater
2010-02-02 23:27 21768一般来讲,我们用LayoutInflater做一件事:infl ... -
Android's Components 生命周期
2010-02-02 23:27 2110Android中,Component(activity、ser ... -
Activity文档翻译
2010-02-02 23:26 1540转自:http://www.blogjava.net/m ... -
Intent
2010-01-20 10:51 011 public class MumActivity ex ... -
aidl
2010-01-05 11:24 30271. android进程之间如何通讯呢(在不同的进程中怎样传递 ... -
Gallery 画廊
2009-12-17 20:25 33291. images.xml <?xml ver ...
相关推荐
现今很流行的 TabHost的各种实现方式的代码
TabHost中填充自定义ListView
tabhost中嵌套一个tabhost。
TabHost的使用方法,适合初学者,适合课堂讲授实现模拟显示未接来电、已接来电和拨出电话的选项卡。
TabHost+ViewPager实现滑动tabhost, viewPager;tabhost;滑动;源码
Android 嵌套TabHost示例. 两层TabHost嵌套,实现的效果类似网页上的二级菜单栏。
tabhost标签页面简单实现,这是学习android初期做的demo,
tabhost页面跳转需要用到的tabhost单例模式小例子,也有tabhost底部的布局
Android TabHost TabActivity TabHost的简单使用
Android TabHost实现屏幕UI窗口的TAB切换功能,实现的过程:声明TabHost对象、取得TabHost对象,为TabHost添加标签,新建一个newTabSpec(newTabSpec),设置其标签和图标(setIndicator),设置内容(setContent),然后...
ViewPager和Tabhost结合,可滑动的tabhost源代码,是一个很不错的Android源码,有兴趣的伙伴们抽时间可以看一下把
TabHost分页简单应用,以及解决TabHost下面白线问题.
android Tabhost使用Demo
1、底部tabhost嵌套顶部tabhost. 2、顶部tabhost,嵌套listview。 3、顶部tabhost子tab选项仿网易新闻功能,可以滑动,每一个对应一个listvie
Android TabHost TabWidget 切换卡
android-->tabHost 源码
androidTabhost的使用实例代码,仅供参考
TabHost实现底部菜单, 底部菜单选项卡主要是通过TabHost和RadioGroup实现
android TabHost(标签)的使用 简单实例。
TabHost布局的框架,点击button按钮切换页面、随即更改字体颜色和背景图片。