Android 实现分页(使用TabWidget/TabHost)
注:本文为转载,但该内容本人已亲身尝试,确认该方法可行,代码有点小的改动,转载用作保存与分享。
原作者地址:http://gundumw100.iteye.com/blog/853967
个人吐嘈:据说TabWidget已经过时了,取而代之的是Fragment,但关于这个Fragment暂时还没时间研讨,现使用的是TabWidget方法,个人感觉实现出来的效果还是很不错的。
自定义TabHost:不用继承TabActivity,具体代码如下:
定义布局文件:activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TabHost01" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:orientation="vertical" android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
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">
<LinearLayout android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="two"
android:id="@+id/TextView02" android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ScrollView
android:id="@+id/Scroll01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:background="@android:color/white" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:id="@+id/title01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="20sp"
android:text="员工信息查询测试"
android:padding="5dp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:textSize="20sp"
android:text="测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n测试\n"
android:layout_weight="1"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:text="three"
android:id="@+id/TextView03" android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
编写Java代码:
package com.example.test2; import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.TabHost; public class MainActivity extends Activity {
/** Called when the activity is first created. */
private TabHost tabHost; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try{
tabHost = (TabHost) this.findViewById(R.id.TabHost01);
tabHost.setup(); tabHost.addTab(tabHost.newTabSpec("tab_1")
.setContent(R.id.LinearLayout1)
//.setIndicator("TAB1",this.getResources().getDrawable(R.drawable.img01)));
.setIndicator("TAB1"));
tabHost.addTab(tabHost.newTabSpec("tab_2")
.setContent(R.id.LinearLayout2)
//.setIndicator("TAB2",this.getResources().getDrawable(R.drawable.img01)));
.setIndicator("TAB2"));
tabHost.addTab(tabHost.newTabSpec("tab_3")
.setContent(R.id.LinearLayout3)
//.setIndicator("TAB3",this.getResources().getDrawable(R.drawable.img01)));
.setIndicator("TAB3"));
tabHost.setCurrentTab(1);
}catch(Exception ex){
ex.printStackTrace();
Log.d("EXCEPTION", ex.getMessage());
} }
}
运行图:

本人提供Demo下载:点击此处下载Demo
-全文完-
Android 实现分页(使用TabWidget/TabHost)的更多相关文章
- Android:简单实现ViewPager+TabHost+TabWidget实现导航栏导航和滑动切换
viewPager是v4包里的一个组件,可以实现滑动显示多个界面. android也为viewPager提供了一个adapter,此adapter最少要重写4个方法: public int getCo ...
- Android使用Fragment来实现TabHost的功能(解决切换Fragment状态不保存)以及各个Fragment之间的通信
以下内容为原创,转载请注明:http://www.cnblogs.com/tiantianbyconan/p/3360938.html 如新浪微博下面的标签切换功能,我以前也写过一篇博文(http:/ ...
- Android --ListView分页
参考博客:Android ListView分页加载(服务端+android端)Demo 监听OnScrollListener事件 class OnListScrollListener implemen ...
- Android ListView分页载入(服务端+android端)Demo
Android ListView分页载入功能 在实际开发中经经常使用到,是每一个开发人员必须掌握的内容,本Demo给出了服务端+Android端的两者的代码,并成功通过了測试. 服务端使用MyEcli ...
- android开发之如何使TabHost的TabWidget位于屏幕下方
更改TabHost里的第一个LinearLayout为RelativeLayout.并在TabWidget中添加android:layout_alignParentBottom="true& ...
- 【Android基础篇】TabWidget设置背景和字体
在使用TabHost实现底部导航栏时,底部导航栏的三个导航button无法在布局文件中进行定制.比方设置点击时的颜色.字体的大小及颜色等,这里提供了一个解决的方法.就是在代码里进行定制. 思路是在Ac ...
- Android studio 中的TabWidget
1.TabWidget 的 layout文件 <?xml version="1.0" encoding="utf-8"?> <TabHost ...
- Android开发之自己定义TabHost文字及背景(源码分享)
使用TabHost 能够在一个屏幕间进行不同版面的切换,而系统自带的tabhost界面较为朴素,我们应该怎样进行自己定义改动优化呢 MainActivity的源码 package com.dream. ...
- Android之分页加载数据
基本的原理和我的上一篇随笔“Android之下拉刷新ListView”差不多,代码里面有注释,这里就不废话了,直接上代码. 自定义的分页显示ListView——PagedListView.java代码 ...
随机推荐
- CentOS 6.3下Samba服务器的安装与配置
一.简介 Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件,而SMB是Server Message Block的缩写,即为服务器消息块 ,SMB主要是作为Microsoft的 ...
- WPF Tranform-Flip Image
Use a ScaleTransform with a ScaleX of -1 for horizontal and ScaleY of -1 for vertical flipping, appl ...
- 利用firebug调试功能辅助了解闭包和this
算一算,有段时间没写博客. 上午的时候翻看以前收藏的一个系列博文<深入理解javascript原型和闭包>, 讲闭包那节:http://www.cnblogs.com/wangfupeng ...
- 百度地图API显示多个标注点并添加百度样式检索窗口
原作者博客地址:http://blog.csdn.net/a497785609/article/details/24009031 在此基础上进行了修改: 1.添加闭包,将i传入内部 2.添加地图和卫星 ...
- JS控制div跳转到指定的位置的解决方案总结
总结一下自己在写这个需求遇到的问题,相信大家应该是经常遇到的.即要求滚轮滚动到指定的位置.先看下基本的解决方案. 1.给链接a加个#的方式来实现跳转.(锚点方法)这里直接贴下代码: html页面: & ...
- CF724D. Dense Subsequence[贪心 字典序!]
D. Dense Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- NYOJ 105
九的余数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 现在给你一个自然数n,它的位数小于等于一百万,现在你要做的就是求出这个数整除九之后的余数. 输入 第一行有一个整 ...
- vuejs的动态过滤
想要通过vuejs动态过滤(这里动态指得是过滤的条件是动态变化的), 一直没找到好办法, 最蠢的办法当然是两个两个数组,一个作为原始副本数组 一个作为视图数组,这样当过滤条件变化的时候 动态拷贝原始数 ...
- 【转】【C#】迭代器
迭代器模式是设计模式中行为模式(behavioral pattern)的一个例子,他是一种简化对象间通讯的模式,也是一种非常容易理解和使用的模式.简单来说,迭代器模式使得你能够获取到序列中的所有元素而 ...
- 【ASP.NET实战教程】基于ASP.NET技术下多用户博客系统全程实战开发(NNblog)
岁末主推:牛牛老师主讲,多用户博客系统,基于ASP.NET技术,年后将带来移动业务平台项目项目目标: 打造个性品牌Blogo,定制多用户博客 为每一个博客用户提供个性化的 blogo解决方案,打造精品 ...