如何简单的实现一个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选择器 缺点:只有 ...
随机推荐
- Unity3d之MonoBehavior的各个函数的执行顺序,回调,顺序,次数等
Update 当MonoBehaviour启用时,其Update在每一帧被调用.仅调用一次(每帧) LateUpdate 当Behaviour启用时, 每帧调用一次: FixedUpdate 当Mo ...
- android intent打开各种文件的方法
android intent打开各种文件的方法 1./** * 检测是否安装了某个软件 * * @param pkgName "com.bill99.kuaishua" ...
- Android SDK 目录说明
Android SDK目录说明: AVD Manager.exe:虚拟机管理工具 SDK Manager.exe:sdk管理工具 tools目录:包括测试.调试.第三方工具.模拟器.数据管理工具等. ...
- mysql-cluster集群(亲测)
重要说明:mysql-cluste与非集群时用的mysql-server与mysql-client没有任何关系,mysql-cluste安装包中已自带了集群用的server与client,启动mysq ...
- 项目中的.Net
一.@符号的妙用 1.字符串转义符 源:'\'在C#中是特殊符号,表示转义字符,所有要表示普通字符串'\',则需要用'\\',通过@符号,可以实现'\'当做普通字符使用,如下: str ...
- 级联关系(内容大部分来自JavaEE轻量型解决方案其余的是我的想法)
1. 级联关系 在Hibernate程序中持久化的对象之间会通过关联关系互相引用.对象进行保存.更新和删除等操作时,有时需要被关联的对象也执行相应的操作,如:假设需要关联关系的主动方对象执行操作时,被 ...
- 一个人的安全部之ELK接收Paloalto日志并用钉钉告警
起因 通报漏洞后,开发未能及时修复漏洞,导致被攻击,领导说我发现被攻击的时间晚了,由于一个人安全部精力有限未能及时看IPS告警,于是做了个钉钉告警. 本人环境介绍 ubuntu 14.04 pytho ...
- 在CcentOS系统上将deb包转换为rpm包
deb文件格式本是ubuntu/debian系统下的安装文件,那么我想要在redhat/centos/fedora中安装,需要把deb格式的软件包转化成rpm格式. 需要用到的转换工具:alien_8 ...
- 在使用springMVC时,我使用了@Service这样的注解,发现使用注解@Transactional声明的事务不起作用
问题出现的场景: 在使用spring mvc时,我使用了@Service这样的注解, 发现使用注解@Transactional声明的事务不起作用. 我的配置如下: <mvc:annotation ...
- spring-hadoop-samples
官方的spring-hadoop-samples的demo 写的还是挺好的,值得学习. 官网地址: http://projects.spring.io/spring-hadoop/#quick-sta ...