如何简单的实现一个tab页title的动画效果
首先我们来看看实现的效果 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的动画效果的更多相关文章
- 高仿京东到家APP引导页炫酷动画效果
前言 京东到家APP的引导页做的可圈可点,插画+动效,简明生动地说明了APP最吸引用户的几个亮点(商品多,价格低,配送快...).本文主要分析拆解这些动画效果,并完成一个高仿Demo,完整的Demo代 ...
- 利用jquery写的一个TAB页切换效果
函数如下 /** *切换效果 */ function switab(tab,con,tab_c_css,tab_n_css,no) { $(tab).each(function(i){ if(i == ...
- 一个加载时带动画效果的ListBoxItem
今天我们来谈一下ListBoxItem这个控件,ListBoxItem是直接从ContentControl继承而来的,所以可以添加到任何具有Content属性的控件中去,常见的ListBoxItem可 ...
- presentModalViewController方法,present一个透明的viewController,带动画效果
//假设需要被present的控制器实例为controller,controller的背景色设置为clearColor UIViewController * rootcontroller = self ...
- tab页切换
做了一个tab页切换.点击不同tab,显示对应的内容信息 如图 =================HTML===================== <!doctype html public ...
- Easyui 实现点击不同树节点打开不同tab页展示不同datagrid表数据设计
实现点击不同树节点打开不同tab页展示不同datagrid表数据设计 by:授客 QQ:1033553122 测试环境 jquery-easyui-1.5.3 需求描述 如上图, 1.点击左侧树,叶子 ...
- SPA项目开发之tab页实现
实现思路及细节 1.利用前面博客所讲的Vuex的知识:定义几个变量 Options:存放tab页对象的容器(主要是路由路径以及tab页的名字) activeIndex:被激活的tab页路由路径 sho ...
- JQuery实现tab页
用ul 和 div 配合实现tab 页 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="U ...
- 用CSS实现Tab页切换效果
用CSS实现Tab切换效果 最近切一个页面的时候涉及到了一个tab切换的部分,因为不想用js想着能不能用纯CSS的选择器来实现切换效果.搜了一下大致有下面三种写法. 利用:hover选择器 缺点:只有 ...
随机推荐
- 集合框架(06)Arrays
Arrays Arrays:用于操作数组的工具类,里面都是静态方法 ---数组变集合 1.asList:将数组变成List集合 把数组变成list集合的好处?可以使用集合的思想和方法来操作数组中的元素 ...
- INFORMATION_SCHEMA获取数据库的信息
简介 information_schema这张数据表保存了MySQL服务器所有数据库的信息.如数据库名,数据库的表,表栏的数据类型与访问权限等.再简单点,这台mysql服务器上,到底有哪些数据库.各个 ...
- 解魔方的机器人攻略15 – 安装 Eclipse
由 动力老男孩 发表于 2009/12/27 17:40:49 在远古时代,程序员们通常用写字板来编写Java程序,然后用Javac.exe和Java.exe来编译和执行.对于NXT来说,对应的命令是 ...
- Javascript中的原型链、prototype、__proto__的关系
javascript 2016-10-06 1120 9 上图是本宝宝用Illustrator制作的可视化信息图,希望能帮你理清Javascript对象与__proto__.prototype和 ...
- Oracle truncate、 delete、 drop区别
相同点: 1.truncate和不带where子句的delete.以及drop都会删除表内的数据. 2.drop.truncate都是DDL语句(数据定义语言),执行后会自动提交. 不同点: 1. t ...
- 设计模式之装饰器模式(PHP实现)
/** * 装饰器模式(Decorator Pattern)允许向一个现有的对象添加新的功能,同时又不改变其结构.这种类型的设计模式属于结构型模式,它是作为现有的类的一个包装. * 这种模式创建了一个 ...
- 设计模式之桥接模式(php实现)
github地址:https://github.com/ZQCard/design_pattern /** * 桥接模式 * 优点: * 1.分离抽象接口及其实现部分.提高了比继承更好的解决方案. * ...
- CentOS6.5安装ganglia3.6
参考来源: 1.http://yhz.me/blog/Install-Ganglia-On-CentOS.html 2.http://blog.csdn.net/sdlyjzh/article/det ...
- 2017.7.7 在eclipse中快速查找类:ctrl+shift+T
快捷键:ctrl+shift+T,用于快速找到某个类.
- Java模式的秘密--java常用的几种模式
要学习设计模式,首先要明白设计模式,就是为实现某一种或某一组功能提供的代码编码方式.它没有固定的套路,只有约定俗成的风格.所有编码者可以根据已有的设计模式开放思维,设计出自己的设计模式,也会在无意中使 ...