Android下实现tab页个人比较推崇的方法
使用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页个人比较推崇的方法的更多相关文章
- Android ActionBar 关于tab的应用 以及 TabListener的方法详解
actionBar的tab标签应用以及TabListener的方法详解 package com.example.actionBarTest.actionBarTab; import android.a ...
- JS组件系列——基于Bootstrap Ace模板的菜单Tab页效果优化
前言:之前发表过一篇 JS组件系列——基于Bootstrap Ace模板的菜单和Tab页效果分享(你值得拥有) ,收到很多园友的反馈,当然也包括很多诟病,因为上篇只是将功能实现了,很多细节都没有处理 ...
- SPA项目开发之tab页实现
实现思路及细节 1.利用前面博客所讲的Vuex的知识:定义几个变量 Options:存放tab页对象的容器(主要是路由路径以及tab页的名字) activeIndex:被激活的tab页路由路径 sho ...
- Android 常用UI控件之TabHost(5)Tab栏在底部且在最上层也不盖tab页
tab栏在底部 <TabHost android:id="@android:id/tabhost" android:layout_width="match_pare ...
- Activity“ 阻止自动弹出软键盘”的方法 -尤其是对于Tab页下的!
我的activity是Tab页签下的~! 所以应把代码加在继承于TabActivity的那个activity中!!而不是由点击Tab页启动的那个activity <activity androi ...
- [原创]Android自定义View之IndicatorView,显示当前tab页所处位置的View
概述 Android IndicatorView的灵感来源于SlidingTabView,虽然有句"不重复"造轮子在先,本着练手的目的,还是写了一个功能较为简单的类似view. 其 ...
- Android UI--ViewPager扩展Tab标签指示
Android UI--ViewPager扩展Tab标签指示 2013年8月30日出来冒冒泡 ViewPager这个控件已经不算是陌生的了,各种玩Android的小伙伴们都有发表相应的文章来讲它.我看 ...
- JS组件系列——基于Bootstrap Ace模板的菜单和Tab页效果分享(你值得拥有)
前言:最近园子里多了许多谈语言.谈环境.谈逼格(格局)的文章,看看笑笑过后,殊不知其实都是然并卵.提升自己的技术才是王道.之前博主分享过多篇bootstrap组件的文章,引起了很多园友的关注和支持,看 ...
- 在bootstrap ace样式框架上修改的后台管理型模板(Tab页后台管理模板)
后台管理模板开始用frameset布局,但是有时候会遮挡比如上面导航或者左边导航的二级三级弹出菜单,因为宽度被限制了,所以有时候就用easyui或者ext的,但是样式不好看,然后看到了bootstra ...
随机推荐
- [你必须知道的.NET]第三十一回,深入.NET 4.0之,从“新”展望
发布日期:2009.05.22 作者:Anytao © 2009 Anytao.com ,Anytao原创作品,转贴请注明作者和出处. /// <summary> /// 本文开始,将以& ...
- jsp中利用checkbox进行批量删除
一.将前台jsp页面中的所有你要用到checkbox的name值设为相同,如 <input type="checkbox" name="userid"&g ...
- Hadoop基础教程之重新认识Hadoop
之前,我们把hadoop从下载包部署到编写了helloworld,看到了结果.现是得开始稍微更深入地了解hadoop了. Hadoop包含了两大功能DFS和MapReduce, DFS可以理解为一 ...
- iOS 开发--NSMutableArray使用枚举方法
可变数组也可以使用枚举方法, 我们在这里提供了两种枚举方法, 一个是正序枚举, 一个是倒序枚举, 在正序枚举中, 元素的个数和顺序都是不可以修改的, 但是在倒序枚举中却可以修改, 这有些耐人寻味. 涉 ...
- JavaPersistenceWithHibernate第二版笔记-第四章-Mapping persistent classes-001区分entities and value types
一.介绍 1.这种引用方式不对,但删除时不能级联 要这种引用方式 2.The Bid class could be a problem. In object-oriented modeling, th ...
- Java-马士兵设计模式学习笔记-观察者模式-模拟Awt Button
一.概述 Java 的Awt是 Observer模式,现用Java自己模拟awt中Button的运行机制 二.代码 1.Test.java import java.text.DateFormat; i ...
- 将EXE作为资源,然后在释放到磁盘上并运行该exe程序(使用了FindResource,LoadResource,然后用CFile写成一个文件)
// 将exe作为资源加入,然后再释放出来,并运行 try { HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(IDR_EXE1), _T(" ...
- JavaWeb笔记——JSTL标签
JSTL 1. jstl的概述 * apache的东西,依赖EL * 使用jstl需要导入jstl.jar.standard.jar * 四大库: > core:核心库,重点 ...
- Linux命令-dd
dd命令用于指定大小的拷贝的文件或指定转换文件. 以下命令作用:将光驱设备拷贝成镜像文件 参数 if 输入的文件名称 参数 of 输出的文件名称 [root@localhost testA]# dd ...
- Flex通过Blazeds利用Remoteservice与后台java消息推送
http://www.cnblogs.com/xia520pi/archive/2012/05/26/2519343.html http://computerdragon.blog.51cto.com ...