GooglePlay 首页效果----tab的揭示效果(Reveal Effect) (1)

前言:

无意打开GooglePlay app来着,然后发现首页用了揭示效果,连起来用着感觉还不错.

不清楚什么是揭示效果(Reveal Effect)的效果可以看我前面一篇文章:Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果

无法使用Google的小伙伴可以看我更前面的文章:提高(Android)开发效率的工具与网站

工具与分析

  • GooglePlay App,这个自己安装好吧,
  • 工具 uiautomatorviewer.bat,ui分析的工具,在Android sdk的tools目录,建议鼠标右键给它在桌面建个快捷方式,下次桌面双击就可以使用了,非常方便.

要点:

  • 揭示动画 ViewAnimationUtils.createCircularReveal()
  • TabLayout 的使用(修改)
  • 获取view点击的坐标(用于做动画)

效果展示(动画的颜色是随机的)

demo地址: https://github.com/didikee/Demos

墙内的小伙伴可以试试 APKPure,一个墙内可以使用,资源是GooglePlay的,缺点:下载慢,优点:能下....(无言以对...)

界面布局:

  1. <LinearLayout
  2. android:id="@+id/activity_google_play_tab_reveal"
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. xmlns:app="http://schemas.android.com/apk/res-auto"
  5. xmlns:tools="http://schemas.android.com/tools"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent"
  8. android:orientation="vertical"
  9. tools:context="com.didikee.demos.ui.act.viewActivity.GooglePlayTabRevealActivity"
  10. >
  11. <FrameLayout
  12. android:layout_width="match_parent"
  13. android:layout_height="140dp">
  14. <FrameLayout
  15. android:id="@+id/below"
  16. android:layout_width="match_parent"
  17. android:layout_height="match_parent">
  18. <View
  19. android:id="@+id/act_view"
  20. android:layout_width="match_parent"
  21. android:layout_height="match_parent"/>
  22. </FrameLayout>
  23. <com.didikee.demos.ui.tab.ExtTabLayout
  24. android:id="@+id/sliding_tabs"
  25. android:layout_width="match_parent"
  26. android:layout_height="48dp"
  27. android:layout_gravity="bottom"
  28. app:tabGravity="fill"
  29. app:tabIndicatorHeight="1dp"
  30. app:tabMode="fixed"
  31. app:tabSelectedTextColor="@color/colorAccent"
  32. app:tabTextColor="@color/white"/>
  33. </FrameLayout>
  34. <android.support.v4.view.ViewPager
  35. android:id="@+id/viewpager"
  36. android:layout_width="match_parent"
  37. android:layout_height="wrap_content"
  38. android:background="@color/bisque"
  39. app:layout_behavior="@string/appbar_scrolling_view_behavior"
  40. />
  41. </LinearLayout>

重点是FrameLayout和它内部的子View.

  1. <FrameLayout
  2. android:id="@+id/below"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5. <View
  6. android:id="@+id/act_view"
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent"/>
  9. </FrameLayout>

子view负责执行动画,FrameLayout负责在子view执行完动画后变成子view执行动画的颜色,这样就能达到一直无限切换的假象

这个模式和GooglePlay保持了一致,你可以打开uiautomatorviewer看看Google的布局.

java实现

这里有个要说明的细节,可能细心的同学会发现,执行动画的起始位置和你手指点击的位置有关,这里的实现的以手指抬起的坐标为执行动画的起点.

GooglePlay的tab不知道是什么写的,我个人感觉不是TabLayout,因为tabLayout默认点击是会有涟漪效果的,但是GooglePlay的tab点击了却没有,我也不想纠结它是用什么做的,我比较偏好TabLayout,所以我就用TabLayout去实现.

插一句,关于Android自定义View的三种方式o((≧▽≦o)

1. 继承 ViewGroup

2. 继承 View

3. 拷贝源码,然后改改...(~ o ~)~zZ

今天,用第三种................

获取TabLayout点击tab时的坐标:

拷贝Tablayout源码到自己的工程(不要学我....)

TabLayout的组成:

TabLayout

TabView //每个item元素view

SlidingTabStrip //每个item下有一条线,也是一个view

我的目标是 TabView,在tabView Selected 的时候将(即调用 mTab.select();)坐标也一起传出去.于是我添加一个接口.

  1. //--------------add listener
  2. public interface LocationListener{
  3. void location(float x,float y,int tabHeight);
  4. }
  5. private MyExtTabLayout.LocationListener locationListener;
  6. public void setLocationListener(MyExtTabLayout.LocationListener locationListener) {
  7. this.locationListener = locationListener;
  8. }
  9. //------------add listener end

在tab选中时传出坐标:

  1. @Override
  2. public boolean onTouchEvent(MotionEvent event) {
  3. if (event.getAction()==MotionEvent.ACTION_UP){
  4. x=event.getRawX();
  5. y=event.getRawY();
  6. }
  7. return super.onTouchEvent(event);
  8. }
  9. @Override
  10. public boolean performClick() {
  11. final boolean value = super.performClick();
  12. if (mTab != null) {
  13. if (locationListener!=null)locationListener.location(x,y,getHeight());
  14. mTab.select();
  15. return true;
  16. } else {
  17. return value;
  18. }
  19. }

执行动画

有了坐标就可以执行动画了,动画比较简单.和之前的一篇没多大区别,只是这次我改了执行动画的起始坐标,变成了动态的了.

完整代码:

  1. private ViewPager viewPager;
  2. private SimpleFragmentPagerAdapter pagerAdapter1;
  3. private ExtTabLayout tabLayout;
  4. private View viewAnimate;
  5. private View below;
  6. private float x;
  7. private float y;
  8. private int height;
  9. private int belowColor;
  10. private int systemStatusBarHeight;
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_google_play_tab_reveal);
  15. setBarStyle();
  16. below = findViewById(R.id.below);
  17. viewAnimate = findViewById(R.id.act_view);
  18. systemStatusBarHeight = DisplayUtil.getSystemStatusBarHeight(this);
  19. pagerAdapter1 = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), new
  20. String[]{"tab1", "tab2", "tab3", "tab4"});
  21. viewPager = (ViewPager) findViewById(R.id.viewpager);
  22. tabLayout = (ExtTabLayout) findViewById(R.id.sliding_tabs);
  23. tabLayout.setupWithViewPager(viewPager);
  24. tabLayout.setTabMode(ExtTabLayout.MODE_FIXED);
  25. viewPager.setAdapter(pagerAdapter1);
  26. belowColor = Color.parseColor(ColorUtil.random());
  27. below.setBackgroundColor(belowColor);
  28. viewAnimate.setBackgroundColor(belowColor);
  29. tabLayout.setLocationListener(new ExtTabLayout.LocationListener() {
  30. @Override
  31. public void location(float x, float y, int tabHeight) {
  32. GooglePlayTabRevealActivity.this.x = x;
  33. GooglePlayTabRevealActivity.this.y = y;
  34. GooglePlayTabRevealActivity.this.height = tabHeight;
  35. }
  36. });
  37. tabLayout.addOnTabSelectedListener(new ExtTabLayout.OnTabSelectedListener() {
  38. @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
  39. @Override
  40. public void onTabSelected(ExtTabLayout.Tab tab) {
  41. Log.e("test", "x: " + x + " y: " + y + " height: " + height);
  42. final int width = viewAnimate.getWidth();
  43. final int height = viewAnimate.getHeight();
  44. final double radio = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
  45. float centerX = x;
  46. float centerY = y;
  47. Animator circularReveal = ViewAnimationUtils.createCircularReveal(viewAnimate,
  48. (int) centerX,
  49. (int) centerY, 0, (float) radio);
  50. circularReveal.setInterpolator(new AccelerateInterpolator());
  51. circularReveal.setDuration(375);
  52. circularReveal.addListener(new Animator.AnimatorListener() {
  53. @Override
  54. public void onAnimationStart(Animator animation) {
  55. belowColor = Color.parseColor(ColorUtil.random());
  56. viewAnimate.setBackgroundColor(belowColor);
  57. }
  58. @Override
  59. public void onAnimationEnd(Animator animation) {
  60. below.setBackgroundColor(belowColor);
  61. }
  62. @Override
  63. public void onAnimationCancel(Animator animation) {
  64. }
  65. @Override
  66. public void onAnimationRepeat(Animator animation) {
  67. }
  68. });
  69. circularReveal.start();
  70. }
  71. @Override
  72. public void onTabUnselected(ExtTabLayout.Tab tab) {
  73. }
  74. @Override
  75. public void onTabReselected(ExtTabLayout.Tab tab) {
  76. }
  77. });
  78. }
  79. public void setBarStyle() {
  80. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  81. // 设置状态栏透明
  82. getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  83. }
  84. }
  85. public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {
  86. private String tabTitles[];
  87. public SimpleFragmentPagerAdapter(FragmentManager fm, String[] strings) {
  88. super(fm);
  89. tabTitles = strings;
  90. }
  91. @Override
  92. public Fragment getItem(int position) {
  93. return PageFragment.newInstance(position + 1);
  94. }
  95. @Override
  96. public int getCount() {
  97. return tabTitles.length;
  98. }
  99. @Override
  100. public CharSequence getPageTitle(int position) {
  101. return tabTitles[position];
  102. }
  103. }
  104. @Override
  105. protected void onDestroy() {
  106. super.onDestroy();
  107. viewAnimate.clearAnimation();
  108. }

最后,demo在我的github上,地址是: https://github.com/didikee/Demos

喜欢的点个赞啦

GooglePlay 首页效果----tab的揭示效果(Reveal Effect) (1)的更多相关文章

  1. Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果

    Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果 前言: 每次写之前都会来一段(废)话.{心塞...} Google Play首页两个tab背景 ...

  2. vue实现tab选项卡切换效果

    tab选项卡切换效果: 通过点击事件传入参数,然后通过v-show来进行切换显示 <template> <div class="box"> <div ...

  3. ViewPager+GridView实现首页导航栏布局分页效果

    如图是效果图用ViewPager+GridView实现首页导航栏布局分页效果来实现的效果 Demo下载地址:http://download.csdn.net/detail/qq_29774291/96 ...

  4. 纯js实现网页tab选项卡切换效果

    纯js实现网页tab选项卡切换效果 百度搜索     js 点击菜单项就可以切换内容的效果

  5. ES6面向对象实现tab栏切换效果

    面向对象实现tab栏切换效果

  6. 页面倒计时跳转页面效果,js倒计时效果

    页面倒计时跳转页面效果,js倒计时效果 >>>>>>>>>>>>>>>>>>>> ...

  7. Android自定义控件----RadioGroup实现APP首页底部Tab的切换

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

  8. 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果

    原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...

  9. 设置TextView的密码效果以及跑马灯效果

    密码效果以及跑马灯效果: xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...

随机推荐

  1. 【疯狂造轮子-iOS】JSON转Model系列之二

    [疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...

  2. 用scikit-learn学习主成分分析(PCA)

    在主成分分析(PCA)原理总结中,我们对主成分分析(以下简称PCA)的原理做了总结,下面我们就总结下如何使用scikit-learn工具来进行PCA降维. 1. scikit-learn PCA类介绍 ...

  3. 在离线环境中使用.NET Core

    在离线环境中使用.NET Core 0x00 写在开始 很早开始就对.NET Core比较关注,一改微软之前给人的印象,变得轻量.开源.跨平台.最近打算试着在工作中使用.但工作是在与互联网完全隔离的网 ...

  4. 移动web基本知识

    1.pixel像素基础 1.px:csspixel 逻辑像素,浏览器所使用的抽象单位 2.dp,pt:设备无关像素 3.devicePixelPatio 设备像素缩放比例 2.viewport 1. ...

  5. Electron使用与学习--(基本使用与菜单操作)

    对于electron是个新手,下面纯属个人理解.如有错误,欢迎指出.   一.安装 如果你本地按照github上的 # Install the `electron` command globally ...

  6. Android数据加密之SHA安全散列算法

    前言: 对于SHA安全散列算法,以前没怎么使用过,仅仅是停留在听说过的阶段,今天在看图片缓存框架Glide源码时发现其缓存的Key采用的不是MD5加密算法,而是SHA-256加密算法,这才勾起了我的好 ...

  7. [干货来袭]MSSQL Server on Linux预览版安装教程(先帮大家踩坑)

    前言 昨天晚上微软爸爸开了全国开发者大会,会上的内容,我就不多说了,园子里面很多.. 我们唐总裁在今年曾今透漏过SQL Server love Linux,果不其然,这次开发者大会上就推出了MSSQL ...

  8. .NET设计模式访问者模式

    一.访问者模式的定义: 表示一个作用于某对象结构中的各元素的操作.它使你可以在不改变各元素类的前提下定义作用于这些元素的新操作. 二.访问者模式的结构和角色: 1.Visitor 抽象访问者角色,为该 ...

  9. C++的内存泄漏检测【转载】

    原文地址: http://www.cnblogs.com/jily/p/6239514.html

  10. [Hadoop in Action] 第5章 高阶MapReduce

    链接多个MapReduce作业 执行多个数据集的联结 生成Bloom filter   1.链接MapReduce作业   [顺序链接MapReduce作业]   mapreduce-1 | mapr ...