首先我们来看看实现的效果 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. Request Header Or Cookie Too Large

    运营反馈 Nginx 报 400 错误,具体点说:Request Header Or Cookie Too Large.其实随便搜搜就知道可以通过加大 client_header_buffer_siz ...

  2. FragmentTransaction的commit的异步操作

    FragmentTransaction是异步的,commit()仅是相当于把操作加入到FragmentManager的队列,然后FragmentManager会在某一个时刻来执行,并不是立即执行.所以 ...

  3. win7/win10+vs2015+pcl1.8.0详细配置方案;

    参考网友的资料整理为更详细的解决方案 一.下载相关文件 1.下载PCL-1.8.0-AllInOne-msvc2015-win64.exe.属性表和PDB和测试pcd文件rabbit.pcd,其中,属 ...

  4. 11款最棒的Linux数据恢复工具

    无论你使用的是台式电脑还是笔记本,需要关注的重点之一都是如何保护好你的宝贵数据.因为总会有各种突发情况使你的系统崩溃,然后你要做的就是恢复数据.不管你怎么想,要是我失去了所有的数据却无法恢复的话,我会 ...

  5. Linux用户配置sudo权限(visudo)

    sudo的工作过程如下: 1,当用户执行sudo时,系统会主动寻找/etc/sudoers文件,判断该用户是否有执行sudo的权限 2,确认用户具有可执行sudo的权限后,让用户输入用户自己的密码确认 ...

  6. HTML5的测试总结

    HTML5其实也是web的一种,所以基本的web测试的一些重点,HTML5上都要过一遍,不过也有其特殊之处. [需求设计测试] 需求是否合理.是否有更好的实现方法或者功能的遗漏,以及原型图测试,包括用 ...

  7. 在使用springMVC时,我使用了@Service这样的注解,发现使用注解@Transactional声明的事务不起作用

    问题出现的场景: 在使用spring mvc时,我使用了@Service这样的注解, 发现使用注解@Transactional声明的事务不起作用. 我的配置如下: <mvc:annotation ...

  8. Section Formula

    https://brilliant.org/wiki/section-formula/

  9. ios开发中APP底部上滑不能调出如WiFi、蓝牙、播放等的设置页面的解决的方法

    在开发的APP中我们通常通过手动底部上滑来调出WiFi.蓝牙.飞行模式等的设置页面.有时我们开发的APP无法调出. 解决的方法: 进入iPhone "设置" --> &quo ...

  10. etcd的原理分析

    k8s集群使用etcd作为它的数据后端,etcd是一种无状态的分布式数据存储集群. 数据以key-value的形式存储在其中. 今天同事针对etcd集群的运作原理做了一个讲座,总结一下. A. etc ...