使用fragment实现tab页的效果:

三个页面是单独的三个Fragment

主Activity的实现:

package com.hsx.tab;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageButton; public class MainActivity extends FragmentActivity {
protected static final String TAG = "MainActivity";
private View currentButton; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); initComponents(); } private void initComponents() {
ImageButton btn_one = (ImageButton) findViewById(R.id.buttom_one);
ImageButton btn_two = (ImageButton) findViewById(R.id.buttom_two);
ImageButton btn_three = (ImageButton) findViewById(R.id.buttom_three); btn_one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment_One fragment_one = new Fragment_One();
ft.replace(R.id.fl_content, fragment_one, MainActivity.TAG);
ft.commit();
setButton(v); }
}); btn_two.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment_Two fragment_two = new Fragment_Two();
ft.replace(R.id.fl_content, fragment_two, MainActivity.TAG);
ft.commit();
setButton(v); }
}); btn_three.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment_Three fragment_three = new Fragment_Three();
ft.replace(R.id.fl_content, fragment_three, MainActivity.TAG);
ft.commit();
setButton(v);
}
}); /**
* 默认第一个按钮点击
*/
btn_one.performClick(); } /**
* 设置按钮的背景图片
*
* @param v
*/
private void setButton(View v) {
if (currentButton != null && currentButton.getId() != v.getId()) {
currentButton.setEnabled(true);
}
v.setEnabled(false);
currentButton = v;
} }

xml的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <LinearLayout
android:id="@+id/buttom_bar_group"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:orientation="horizontal"> <RelativeLayout style="@style/ButtomBar"> <ImageButton
android:id="@+id/buttom_one"
style="@style/ButtomBarImgBtn"
android:background="@drawable/bar_news"
android:contentDescription="@string/app_name" />
</RelativeLayout> <RelativeLayout style="@style/ButtomBar"> <ImageButton
android:id="@+id/buttom_two"
style="@style/ButtomBarImgBtn"
android:background="@drawable/bar_constact"
android:contentDescription="@string/app_name" />
</RelativeLayout> <RelativeLayout style="@style/ButtomBar"> <ImageButton
android:id="@+id/buttom_three"
style="@style/ButtomBarImgBtn"
android:background="@drawable/bar_deynaimic"
android:contentDescription="@string/app_name" />
</RelativeLayout> </LinearLayout> <View
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_above="@id/buttom_bar_group"
android:background="@color/devide_line" /> <FrameLayout
android:id="@+id/fl_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/line" /> </RelativeLayout>

demo下载地址:http://files.cnblogs.com/hsx514/Test_Fragment.zip

Android下实现tab页个人比较推崇的方法的更多相关文章

  1. Android ActionBar 关于tab的应用 以及 TabListener的方法详解

    actionBar的tab标签应用以及TabListener的方法详解 package com.example.actionBarTest.actionBarTab; import android.a ...

  2. JS组件系列——基于Bootstrap Ace模板的菜单Tab页效果优化

    前言:之前发表过一篇  JS组件系列——基于Bootstrap Ace模板的菜单和Tab页效果分享(你值得拥有) ,收到很多园友的反馈,当然也包括很多诟病,因为上篇只是将功能实现了,很多细节都没有处理 ...

  3. SPA项目开发之tab页实现

    实现思路及细节 1.利用前面博客所讲的Vuex的知识:定义几个变量 Options:存放tab页对象的容器(主要是路由路径以及tab页的名字) activeIndex:被激活的tab页路由路径 sho ...

  4. Android 常用UI控件之TabHost(5)Tab栏在底部且在最上层也不盖tab页

    tab栏在底部 <TabHost android:id="@android:id/tabhost" android:layout_width="match_pare ...

  5. Activity“ 阻止自动弹出软键盘”的方法 -尤其是对于Tab页下的!

    我的activity是Tab页签下的~! 所以应把代码加在继承于TabActivity的那个activity中!!而不是由点击Tab页启动的那个activity <activity androi ...

  6. [原创]Android自定义View之IndicatorView,显示当前tab页所处位置的View

    概述 Android IndicatorView的灵感来源于SlidingTabView,虽然有句"不重复"造轮子在先,本着练手的目的,还是写了一个功能较为简单的类似view. 其 ...

  7. Android UI--ViewPager扩展Tab标签指示

    Android UI--ViewPager扩展Tab标签指示 2013年8月30日出来冒冒泡 ViewPager这个控件已经不算是陌生的了,各种玩Android的小伙伴们都有发表相应的文章来讲它.我看 ...

  8. JS组件系列——基于Bootstrap Ace模板的菜单和Tab页效果分享(你值得拥有)

    前言:最近园子里多了许多谈语言.谈环境.谈逼格(格局)的文章,看看笑笑过后,殊不知其实都是然并卵.提升自己的技术才是王道.之前博主分享过多篇bootstrap组件的文章,引起了很多园友的关注和支持,看 ...

  9. 在bootstrap ace样式框架上修改的后台管理型模板(Tab页后台管理模板)

    后台管理模板开始用frameset布局,但是有时候会遮挡比如上面导航或者左边导航的二级三级弹出菜单,因为宽度被限制了,所以有时候就用easyui或者ext的,但是样式不好看,然后看到了bootstra ...

随机推荐

  1. hdu 4345 Permutation 记忆化搜索

    思路:实际上求的是和小于等于n的质数的种类数!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorit ...

  2. Android OpenGL 学习笔记 --开始篇

    转自: http://www.cnblogs.com/TerryBlog/archive/2010/07/09/1774475.html 1.什么是 OpenGL? OpenGL 是个专业的3D程序接 ...

  3. poj 3255(次短路)

    题目链接:http://poj.org/bbs?problem_id=3255 思路:分别以源点1和终点N为源点,两次SPFA求得dist1[i](1到各点的最短距离)以及dist2[i](各点到N的 ...

  4. lintcode:玩具工厂

    题目 工厂模式是一种常见的设计模式.请实现一个玩具工厂 ToyFactory 用来产生不同的玩具类.可以假设只有猫和狗两种玩具.   样例 ToyFactory tf = ToyFactory(); ...

  5. 欧拉工程第51题:Prime digit replacements

    题目链接 题目: 通过置换*3的第一位得到的9个数中,有六个是质数:13,23,43,53,73和83. 通过用同样的数字置换56**3的第三位和第四位,这个五位数是第一个能够得到七个质数的数字,得到 ...

  6. jquery.lazyload用法

    lazyload是jquery的插件,作为延迟加载图片,减压服务器压力. 如何使用: 先把 <script src="jquery.js" type="text/j ...

  7. 创业者拿到融资别高兴太早,当心TS中的优先清算权

    最近创投圈的新闻读起来真是让人有些绝望啊,一家家创业公司接连宣告倒闭,其中不乏一些走在比较后面的“明星企业”,冷不丁冒出点消息,却是创始人发的公告,宣布公司资金链断裂,进入破产清算程序,或被低价并购. ...

  8. POJ1088滑雪

    Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...

  9. C++:异常的处理

    6.4 异常处理 程序中常见的错误分为两大类:编译时期的错误和运行时期的错误. 编译时期的错误比较简单容易发现:主要是语法错误,如关键字拼写错误.缺分号.括号不匹配等 运行时期的错误比较难发现,甚至是 ...

  10. Linux系统中的load average

    1. load average 定义 linux系统中的Load对当前CPU工作量的度量.简单的说是进程队列的长度. Load Average 就是一段时间 (1 分钟.5分钟.15分钟) 内平均 L ...