如何简单的实现一个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选择器 缺点:只有 ...
随机推荐
- 远程debug---远程服务器参数设置
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=25 -jar myboot.jar 或者 java ...
- mysql系列-安装及服务启动
一.window下的安装 详细见官网 https://dev.mysql.com/doc/refman/5.7/en/windows-installation.html 以 MySQL 5.1 免安装 ...
- [bug]The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
写在前面 在模拟请求的时候,如果url为https的,会报这个错误.大概错误就是:基础连接已关闭:无法建立信任关系的SSL / TLS的安全通道. The underlying connection ...
- NAND_FLASH_内存详解与读写寻址方式
一.内存详解 NAND闪存阵列分为一系列128kB的区块(block),这些区块是 NAND器件中最小的可擦除实体.擦除一个区块就是把所有的位(bit)设置为"1"(而所有字节(b ...
- DirectoryServicesCOMException
捕捉到 System.DirectoryServices.DirectoryServicesCOMException Message=该服务器不愿意处理该请求. Source=System.Direc ...
- 使用Python3解压gz、tar、tgz、zip、rar五种格式的压缩文件例子
使用Python3解压如下五种压缩文件:gz.tar.tgz.zip.rar 简介 gz: 即gzip,通常只能压缩一个文件.与tar结合起来就可以实现先打包,再压缩. tar: linux系统下的打 ...
- JDBCUtils工具类
JdbcUtils.java import java.sql.Connection; import java.sql.SQLException; import javax.sql.DataSource ...
- How to support both ipv4 and ipv6 address for JAVA code.
IPv6 have colon character, for example FF:00::EEIf concatenate URL String, IPv6 URL will like: http: ...
- 11. 配置ContextPath【从零开始学Spring Boot】
转载:http://blog.csdn.net/linxingliang/article/details/51637036 spring boot默认是/ ,这样直接通过http://ip:port/ ...
- react-native 调用第三方 SDK
步骤一:android 文件修改 (1)In android/settings.gradle ... include ':VoiceModule', ':app' project(':VoiceMod ...