首先我们来看看实现的效果 tab上的title沉下去的效果

先来看看布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:id="@+id/top_bar"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/layout_item_one"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"> <TextView
android:id="@+id/item_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="全部"
android:layout_centerHorizontal="true"
android:textColor="@color/mainColor"
android:layout_centerInParent="true"/> <View
android:id="@+id/item_one_bar"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="1px"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/mainColor" />
</RelativeLayout> <RelativeLayout
android:id="@+id/layout_item_two"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/item_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="待回答"
android:layout_margin="10dp"
android:textColor="@color/fontTextColor"
android:layout_centerInParent="true"/>
<View
android:id="@+id/item_two_bar"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="1px"
android:background="@color/mainColor"
android:visibility="gone"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_item_three"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/item_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="已回答"
android:layout_margin="10dp"
android:layout_centerInParent="true"
android:textColor="@color/fontTextColor"/>
<View
android:id="@+id/item_three_bar"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="1px"
android:background="@color/mainColor"
android:layout_alignParentBottom="true"
android:visibility="gone"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_item_four"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/item_four"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="已过期"
android:layout_margin="10dp"
android:textColor="@color/fontTextColor"
android:layout_centerInParent="true"/>
<View
android:id="@+id/item_four_bar"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="1px"
android:background="@color/mainColor"
android:layout_alignParentBottom="true"
android:visibility="gone"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_item_five"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/item_five"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="已拒绝"
android:layout_margin="10dp"
android:textColor="@color/fontTextColor"
android:layout_centerInParent="true"/>
<View
android:id="@+id/item_five_bar"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="1px"
android:background="@color/mainColor"
android:layout_alignParentBottom="true"
android:visibility="gone"/>
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_height="1px"
android:background="#ccc"
/>
</LinearLayout>

是不是发现没什么特别,是的没什么特别 , 下面贴出用到的代码

 /**
*
* @param view
*/
public void onClick(View view){
resetTabBg();
switch (view.getId()){
case R.id.layout_item_one:
setTabPage(0);
break;
case R.id.layout_item_two:
setTabPage(1);
break;
case R.id.layout_item_three:
setTabPage(2);
break;
case R.id.layout_item_four:
setTabPage(3);
break;
case R.id.layout_item_five:
setTabPage(4);
break;
}
}
/**
* 重置每个tab
*/
private void resetTabBg() {
int color = getResources().getColor(R.color.fontTextColor);
mTvItemOne.setTextColor(color);
mVItemOneBar.setVisibility(View.GONE);
mTvItemTwo.setTextColor(color);
mVItemTwoBar.setVisibility(View.GONE);
mTvItemThree.setTextColor(color);
mVItemThreeBar.setVisibility(View.GONE);
mTvItemFour.setTextColor(color);
mVItemFourBar.setVisibility(View.GONE);
mTvItemFive.setTextColor(color);
mVItemFiveBar.setVisibility(View.GONE);
} /**
* 跳入某个tab页
* @param i
*/
private void setTabPage(int i){
int color = getResources().getColor(R.color.mainColor);
if(i == 0){
mTvItemOne.setTextColor(color);
mVItemOneBar.setVisibility(View.VISIBLE);
} else if(i == 1){
// hasNew = false;
// checkHasNew();
mTvItemTwo.setTextColor(color);
mVItemTwoBar.setVisibility(View.VISIBLE);
} else if(i == 2){
mTvItemThree.setTextColor(color);
mVItemThreeBar.setVisibility(View.VISIBLE);
} else if(i == 3){
mTvItemFour.setTextColor(color);
mVItemFourBar.setVisibility(View.VISIBLE);
} else if(i == 4){
mTvItemFive.setTextColor(color);
mVItemFiveBar.setVisibility(View.VISIBLE);
}
//切换viewpager页面
mWdPager.setCurrentItem(i);
}

就会发现自动有这个效果了,是不是很简单,是的其实这个只是利用了布局的特点而已.

如果你不想有这个类似这个动画的效果,可以直接在代码中选择  setVisibility(View.INVISIBLE); //占位不显示 和xml中  View 中加上android:visibility="invisible"

 <View
android:id="@+id/item_five_bar"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="1px"
android:background="@color/mainColor"
android:layout_alignParentBottom="true"
android:visibility="invisible"/>

如何简单的实现一个tab页title的动画效果的更多相关文章

  1. 高仿京东到家APP引导页炫酷动画效果

    前言 京东到家APP的引导页做的可圈可点,插画+动效,简明生动地说明了APP最吸引用户的几个亮点(商品多,价格低,配送快...).本文主要分析拆解这些动画效果,并完成一个高仿Demo,完整的Demo代 ...

  2. 利用jquery写的一个TAB页切换效果

    函数如下 /** *切换效果 */ function switab(tab,con,tab_c_css,tab_n_css,no) { $(tab).each(function(i){ if(i == ...

  3. 一个加载时带动画效果的ListBoxItem

    今天我们来谈一下ListBoxItem这个控件,ListBoxItem是直接从ContentControl继承而来的,所以可以添加到任何具有Content属性的控件中去,常见的ListBoxItem可 ...

  4. presentModalViewController方法,present一个透明的viewController,带动画效果

    //假设需要被present的控制器实例为controller,controller的背景色设置为clearColor UIViewController * rootcontroller = self ...

  5. tab页切换

    做了一个tab页切换.点击不同tab,显示对应的内容信息 如图 =================HTML===================== <!doctype html public ...

  6. Easyui 实现点击不同树节点打开不同tab页展示不同datagrid表数据设计

    实现点击不同树节点打开不同tab页展示不同datagrid表数据设计 by:授客 QQ:1033553122 测试环境 jquery-easyui-1.5.3 需求描述 如上图, 1.点击左侧树,叶子 ...

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

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

  8. JQuery实现tab页

    用ul 和 div 配合实现tab 页 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="U ...

  9. 用CSS实现Tab页切换效果

    用CSS实现Tab切换效果 最近切一个页面的时候涉及到了一个tab切换的部分,因为不想用js想着能不能用纯CSS的选择器来实现切换效果.搜了一下大致有下面三种写法. 利用:hover选择器 缺点:只有 ...

随机推荐

  1. 【强连通分量】tarjan算法及kosaraju算法+例题

    阅读前请确保自己知道强连通分量是什么,本文不做赘述. Tarjan算法 一.算法简介 Tarjan算法是一种由Robert Tarjan提出的求有向图强连通分量的时间复杂度为O(n)的算法. 首先我们 ...

  2. Android Developer -- Bluetooth篇 开发实例之四 API详解

    http://www.open-open.com/lib/view/open1390879771695.html 这篇文章将会详细解析BluetoothAdapter的详细api, 包括隐藏方法, 每 ...

  3. Node应用的Systemd启动(转)

    作者: 阮一峰 日期: 2016年3月12日 前面的文章介绍了 Systemd 的操作命令和基本用法,今天给出一个实例,如何使用 Systemd 启动一个 Node 应用. 本文是独立的,不需要前面的 ...

  4. ASIHTTPRequest框架使用总结系列之阿堂教程1(安装配置篇

    在前年,阿堂在<IOS开发系列之阿堂教程:玩转IPhone客户端和Web服务端交互(客户端)实践>一文中,对于ASIHTTPRequest框架有过一些介简单绍,具体链接地址见http:// ...

  5. django10 使用自定义标签配置说明

    1).在app目录下建目录templatetags[不可改名]目录,然后在该目录下建一个空的__init__.py 2).mytags.py 在templatetags下建一个mytags.py,添加 ...

  6. Hibernate中cascade和inverse的作用

    Inverse和cascade是Hibernate映射中最难掌握的两个属性.两者都在对象的关联操作中发挥作用.1.明确inverse和cascade的作用inverse 决定是否把对对象中集合的改动反 ...

  7. Chromatix

    1.Lens Rolloff Correction  透镜衰减矫正 The Lens Rolloff correction takes into account the fact that,with ...

  8. Git历险记(二)——Git的安装和配置

    各位同学,上回Git历险记(一)讲了一个 “hello Git” 的小故事.有的同学可能是玩过了其它分布式版本控制系统(DVCS),看完之后就触类旁通对Git就了然于胸了:也有的同学可能还如我当初入手 ...

  9. Python开发easy忽略的问题

    这篇文章主要介绍了Python程序猿代码编写时应该避免的17个"坑",也能够说成Python程序猿代码编写时应该避免的17个问题,须要的朋友能够參考下 一.不要使用可变对象作为函数 ...

  10. nginx静态资源配置

    解决EE工程中静态文件显示问题 在工程中本地测试没有问题,发现使用nginx配置了路径的页面,会获取不到相应页面的静态文件问题 静态文件的路径类似为: http://localhost:8080/sa ...