GooglePlay 首页效果----tab的揭示效果(Reveal Effect) (1)
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的,缺点:下载慢,优点:能下....(无言以对...)
界面布局:
<LinearLayout
android:id="@+id/activity_google_play_tab_reveal"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.didikee.demos.ui.act.viewActivity.GooglePlayTabRevealActivity"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="140dp">
<FrameLayout
android:id="@+id/below"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/act_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<com.didikee.demos.ui.tab.ExtTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="bottom"
app:tabGravity="fill"
app:tabIndicatorHeight="1dp"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextColor="@color/white"/>
</FrameLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/bisque"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</LinearLayout>
重点是FrameLayout和它内部的子View.
<FrameLayout
android:id="@+id/below"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/act_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</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();)坐标也一起传出去.于是我添加一个接口.
//--------------add listener
public interface LocationListener{
void location(float x,float y,int tabHeight);
}
private MyExtTabLayout.LocationListener locationListener;
public void setLocationListener(MyExtTabLayout.LocationListener locationListener) {
this.locationListener = locationListener;
}
//------------add listener end
在tab选中时传出坐标:
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction()==MotionEvent.ACTION_UP){
x=event.getRawX();
y=event.getRawY();
}
return super.onTouchEvent(event);
}
@Override
public boolean performClick() {
final boolean value = super.performClick();
if (mTab != null) {
if (locationListener!=null)locationListener.location(x,y,getHeight());
mTab.select();
return true;
} else {
return value;
}
}
执行动画
有了坐标就可以执行动画了,动画比较简单.和之前的一篇没多大区别,只是这次我改了执行动画的起始坐标,变成了动态的了.
完整代码:
private ViewPager viewPager;
private SimpleFragmentPagerAdapter pagerAdapter1;
private ExtTabLayout tabLayout;
private View viewAnimate;
private View below;
private float x;
private float y;
private int height;
private int belowColor;
private int systemStatusBarHeight;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_play_tab_reveal);
setBarStyle();
below = findViewById(R.id.below);
viewAnimate = findViewById(R.id.act_view);
systemStatusBarHeight = DisplayUtil.getSystemStatusBarHeight(this);
pagerAdapter1 = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), new
String[]{"tab1", "tab2", "tab3", "tab4"});
viewPager = (ViewPager) findViewById(R.id.viewpager);
tabLayout = (ExtTabLayout) findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setTabMode(ExtTabLayout.MODE_FIXED);
viewPager.setAdapter(pagerAdapter1);
belowColor = Color.parseColor(ColorUtil.random());
below.setBackgroundColor(belowColor);
viewAnimate.setBackgroundColor(belowColor);
tabLayout.setLocationListener(new ExtTabLayout.LocationListener() {
@Override
public void location(float x, float y, int tabHeight) {
GooglePlayTabRevealActivity.this.x = x;
GooglePlayTabRevealActivity.this.y = y;
GooglePlayTabRevealActivity.this.height = tabHeight;
}
});
tabLayout.addOnTabSelectedListener(new ExtTabLayout.OnTabSelectedListener() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onTabSelected(ExtTabLayout.Tab tab) {
Log.e("test", "x: " + x + " y: " + y + " height: " + height);
final int width = viewAnimate.getWidth();
final int height = viewAnimate.getHeight();
final double radio = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
float centerX = x;
float centerY = y;
Animator circularReveal = ViewAnimationUtils.createCircularReveal(viewAnimate,
(int) centerX,
(int) centerY, 0, (float) radio);
circularReveal.setInterpolator(new AccelerateInterpolator());
circularReveal.setDuration(375);
circularReveal.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
belowColor = Color.parseColor(ColorUtil.random());
viewAnimate.setBackgroundColor(belowColor);
}
@Override
public void onAnimationEnd(Animator animation) {
below.setBackgroundColor(belowColor);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
circularReveal.start();
}
@Override
public void onTabUnselected(ExtTabLayout.Tab tab) {
}
@Override
public void onTabReselected(ExtTabLayout.Tab tab) {
}
});
}
public void setBarStyle() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// 设置状态栏透明
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {
private String tabTitles[];
public SimpleFragmentPagerAdapter(FragmentManager fm, String[] strings) {
super(fm);
tabTitles = strings;
}
@Override
public Fragment getItem(int position) {
return PageFragment.newInstance(position + 1);
}
@Override
public int getCount() {
return tabTitles.length;
}
@Override
public CharSequence getPageTitle(int position) {
return tabTitles[position];
}
}
@Override
protected void onDestroy() {
super.onDestroy();
viewAnimate.clearAnimation();
}
最后,demo在我的github上,地址是: https://github.com/didikee/Demos
喜欢的点个赞啦
GooglePlay 首页效果----tab的揭示效果(Reveal Effect) (1)的更多相关文章
- Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果
Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果 前言: 每次写之前都会来一段(废)话.{心塞...} Google Play首页两个tab背景 ...
- vue实现tab选项卡切换效果
tab选项卡切换效果: 通过点击事件传入参数,然后通过v-show来进行切换显示 <template> <div class="box"> <div ...
- ViewPager+GridView实现首页导航栏布局分页效果
如图是效果图用ViewPager+GridView实现首页导航栏布局分页效果来实现的效果 Demo下载地址:http://download.csdn.net/detail/qq_29774291/96 ...
- 纯js实现网页tab选项卡切换效果
纯js实现网页tab选项卡切换效果 百度搜索 js 点击菜单项就可以切换内容的效果
- ES6面向对象实现tab栏切换效果
面向对象实现tab栏切换效果
- 页面倒计时跳转页面效果,js倒计时效果
页面倒计时跳转页面效果,js倒计时效果 >>>>>>>>>>>>>>>>>>>> ...
- Android自定义控件----RadioGroup实现APP首页底部Tab的切换
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...
- 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果
原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...
- 设置TextView的密码效果以及跑马灯效果
密码效果以及跑马灯效果: xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...
随机推荐
- 自定义基于 VLC 的视频播放器
前言(蛋疼的背景故事) 前段时间,接了一个小项目,有个需求是要在系统待机一段时间以后,循环播放 MV(类似于 Windows 系统的屏幕保护). 听到这个需求,我首先想到的是 MediaPlayer ...
- .Net中的AOP系列之构建一个汽车租赁应用
返回<.Net中的AOP>系列学习总目录 本篇目录 开始一个新项目 没有AOP的生活 变更的代价 使用AOP重构 本系列的源码本人已托管于Coding上:点击查看. 本系列的实验环境:VS ...
- 使用 .NET WinForm 开发所见即所得的 IDE 开发环境,实现不写代码直接生成应用程序
直接切入正题,这是我09年到11年左右业余时间编写的项目,最初的想法很简单,做一个能拖拖拽拽就直接生成应用程序的工具,不用写代码,把能想到的业务操作全部封装起来,通过配置的方式把这些业务操作组织起来运 ...
- Log4Net应用问题
问题 一.日志存储方式 1.txt 2.SQLServer数据库 3.log文件 二.项目类型不同 1winFrom 2webFrom 3MVC 4WPF 5控制台 三.切分依据不同 1.空间大小 2 ...
- 让 ASP.NET vNext 在 Mac OS 中飞呀飞。。。
写在前面 阅读目录: 娓娓道来 Install ASP.NET vNext Command Line Tools 安装 Homebrew 使用 Homebrew,安装 KVM Install Subl ...
- 【AutoMapper官方文档】DTO与Domin Model相互转换(中)
写在前面 AutoMapper目录: [AutoMapper官方文档]DTO与Domin Model相互转换(上) [AutoMapper官方文档]DTO与Domin Model相互转换(中) [Au ...
- Joshua Bloch错了? ——适当改变你的Builder模式实现
注:这一系列都是小品文.它们偏重的并不是如何实现模式,而是一系列在模式实现,使用等众多方面绝对值得思考的问题.如果您仅仅希望知道一个模式该如何实现,那么整个系列都会让您失望.如果您希望更深入地了解各个 ...
- Android,通用ListAdapter
优点 不需要每个列表都建立Adapter. 使用效果 Item点击事件使用的是自写的事件机制. mListAdapter = new BaseListAdapter<PromotionsMode ...
- 速算1/Sqrt(x)背后的数学原理
概述 平方根倒数速算法,是用于快速计算1/Sqrt(x)的值的一种算法,在这里x需取符合IEEE 754标准格式的32位正浮点数.让我们先来看这段代码: float Q_rsqrt( float nu ...
- WEB 基础知识(一)
1. 系统架构 1.1 B/S系统架构 1.2 C/S系统架构 1.3 对比与区别 1.3.1 概述 C/S结构,即Client/Server(客户机/服务器)结构,是大家熟知的软件系统体系结构,通过 ...

