使用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. Win32应用程序中文支持

    Settings--Editor---Encoding改为Windows 936 main.cpp中#include "locale.h" winmain中增加一行: setloc ...

  2. Codeforces Round #336 (Div. 2) B. Hamming Distance Sum 计算答案贡献+前缀和

    B. Hamming Distance Sum   Genos needs your help. He was asked to solve the following programming pro ...

  3. 最大 / 小的K个数

    在<剑指offer>上看到的,而且Qunar去年的校招笔试也考了这题,今天晚上去西电腾讯的宣讲会,来宣讲的学长也说他当时一面的时候面试官问了“一亿个数据的最大的十个数”的面试题.今晚就写写 ...

  4. Linux静态库和动态库

    Linux 工具 ❑ GCC: The GNU Compiler Collection, containing the GNU C compiler❑ G++: A C++ compiler, inc ...

  5. CF 253B Two Heaps

    #include<stdio.h> #include<algorithm> #include<map> using namespace std; struct No ...

  6. 学了C语言,如何利用CURL写一个下载程序?—用nmake编译CURL并安装

    在这一系列的前一篇文章学了C语言,如何为下载狂人写一个磁盘剩余容量监控程序?中,我们为下载狂人写了一个程序来监视磁盘的剩余容量,防止下载的东西撑爆了硬盘.可是,这两天,他又抱怨他的下载程序不好用,让我 ...

  7. JavaPersistenceWithHibernate第二版笔记-第四章-Mapping persistent classes-002identity详解

    一.简介 1.You now have three methods for distinguishing references:  Objects are identical if they occ ...

  8. Spring-Boot初始篇

    Spring Boot 项目旨在简化创建产品级的 Spring 应用和服务.你可通过它来选择不同的 Spring 平台.可创建独立的 Java 应用和 Web 应用,同时提供了命令行工具来允许 ‘sp ...

  9. github不小心同步覆盖了本地文件

    昨天不小心github的commit还没push就同步了,导致本地文件被覆盖,一度以为没救了. 后来得微博 @空非无和 @柳烟堆雪 指点,用git reflog 恢复了文件. 事情是这样的... 我在 ...

  10. android AsyncTask异步下载并更新进度条

    AsyncTask异步下载并更新进度条    //如果不是很明白请看上篇文章的异步下载 AsyncTask<String, Integer, String> 第一个参数:String 传入 ...