使用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. Spark源码分析(三)-TaskScheduler创建

    原创文章,转载请注明: 转载自http://www.cnblogs.com/tovin/p/3879151.html 在SparkContext创建过程中会调用createTaskScheduler函 ...

  2. Spark源码编译

    原创文章,转载请注明: 转载自http://www.cnblogs.com/tovin/p/3822995.html spark源码编译步骤如下: cd /home/hdpusr/workspace ...

  3. hadoop 1 testcase运行方法

       转入hadoop2.0后,逐渐忘记了之前做testcase运行的方法,记录一下:    ant -Dtestcase=Test***    如果只运行core包得testcase可以    an ...

  4. java 语法错误 (操作符丢失) 在查询表达式

    遇到的详细问题: a[0]="11"; a[1]="2223"; a[2]="333"; sta.executeUpdate("i ...

  5. 【重走Android之路】【Java面向对象基础(一)】数据类型与运算符

    [重走Android之路][基础篇(一)][Java面向对象基础]数据类型与运算符   1.数据类型介绍 在Java中,数据类型分为两种:基本数据类型和引用类型. 基本数据类型共8种,见下表: 基本数 ...

  6. hadoop 1.2.1 eclipse 插件编译

    hadoop-1.2.1 eclipse插件编译       在ubuntu上进行hadoop相关的开发,需要在eclipse上安装hadoop开发插件.最新释放出的hadoop包含源码的包,以had ...

  7. rc.local自启动学习(转)

    linux有自己一套完整的启动体系,抓住了linux启动的脉络,linux的启动过程将不再神秘. 本文中假设inittab中设置的init tree为: /etc/rc.d/rc0.d/etc/rc. ...

  8. USACO Section 3.2: Feed Ratios

    直接暴力搜 /* ID: yingzho1 LANG: C++ TASK: ratios */ #include <iostream> #include <fstream> # ...

  9. flex 组建重写

    flex历经几个版本的变化,其封装性也越来越规范. 今日flex的学习,总结是组件的重写. 项目中为使组件的针对性,易用性更强 ,免不了要重写组件. 要改变你的对手你的了解你的对手. 一个组件从被ne ...

  10. Eclipse —— 如何修改文件的默认编辑器

    Eclipse下的各类文件各自都有默认的编辑器,但不一定好用.如何指定各种文件的默认编辑器呢? 假如,Properties文件,我不想用Eclipse自带的编辑器,而是使用 Properties Ed ...