
第三方水波纹效果
发布日期:2021-05-07 19:01:18
浏览次数:31
分类:精选文章
本文共 6856 字,大约阅读时间需要 22 分钟。
Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Java
Latest commit on 13 Sep 2016
README.md
CanEffect
android效果库,阴影效果、水纹效果、波纹效果、圆形显示过渡效果等。
##添加依赖
compile 'com.canyinghao:caneffect:1.0.3'
使用方式
1. 实现方法
CanEffect是一个效果库,兼容至sdk11。很多效果都是继承FrameLayout,通过重写draw方法,画图绘制的。圆形显示过渡的效果,在sdk21及以上可使用系统自带的效果,以下是通过drawChild绘制的,但包装成了与系统相似的方法,用法一致。
public final class ViewAnimationUtils { public static Animator createCircularReveal(View view, int centerX, int centerY, float startRadius, float endRadius) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return android.view.ViewAnimationUtils .createCircularReveal(view, centerX, centerY, startRadius, endRadius); } else { return CanCircularRevealLayout.Builder.on(view) .centerX(centerX) .centerY(centerY) .startRadius(startRadius) .endRadius(endRadius) .create(); } }}
2. 使用方法
其它的阴影效果、水纹效果、波纹效果,使用方法如出一辙。 一些使用中的坑: 1.不要给CanRippleLayout、CanWaterWaveLayout添加点击或长按事件,不然它的子view接受不到事件。 2.如果使用了CanAdapter库,并且使用的是CanRVAdapter类,不要将CanRippleLayout、CanWaterWaveLayout放在item的最外层,CanRVAdapter的item的最外层view默认给了一个点击一个长按事件。
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View view1 = findViewById(R.id.view1); View fl1 = findViewById(R.id.fl1); View view2 = findViewById(R.id.view2); View fl2 = findViewById(R.id.fl2); final View view3 = findViewById(R.id.view3); final View view4 = findViewById(R.id.view4); CanShadowDrawable.Builder.on(fl1) .radius(dp2Px(5)) .shadowColor(Color.parseColor("#333333")) .shadowRange(dp2Px(5)) .offsetTop(dp2Px(5)) .offsetBottom(dp2Px(5)) .offsetLeft(dp2Px(5)) .offsetRight(dp2Px(5)) .create(); CanRippleLayout.Builder.on(view1).rippleCorner(dp2Px(5)).create(); view1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(getApplicationContext(), "onClick", Toast.LENGTH_SHORT).show(); } }); CanShadowDrawable.Builder.on(fl2) .radius(dp2Px(10)) .shadowColor(Color.parseColor("#333333")) .shadowRange(dp2Px(5))// .offsetTop(dp2Px(5)) .offsetBottom(dp2Px(5)) .offsetLeft(dp2Px(5)) .offsetRight(dp2Px(5)) .create(); CanWaterWaveLayout.Builder.on(view2).create(); view2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(getApplicationContext(), "onClick", Toast.LENGTH_SHORT).show(); } }); view3.setVisibility(View.GONE); view4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { view4.setVisibility(View.GONE); view3.setVisibility(View.VISIBLE); Animator c1a = ViewAnimationUtils .createCircularReveal(view3, 0, 0, (int) dp2Px(100), 1000); c1a.setDuration(1000); c1a.setInterpolator(new AccelerateDecelerateInterpolator()); c1a.start(); } }); view3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Animator c1a = ViewAnimationUtils .createCircularReveal(view3, 0, 0, 1000, (int) dp2Px(100)); c1a.setDuration(1000); c1a.setInterpolator(new AccelerateDecelerateInterpolator()); c1a.start(); c1a.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { view3.setVisibility(View.GONE); view4.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); } }); } float dp2Px(float dp) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.action_1: startActivity(new Intent(MainActivity.this, ShadowActivity.class)); break; case R.id.action_2: startActivity(new Intent(MainActivity.this, WaterActivity.class)); break; case R.id.action_3: startActivity(new Intent(MainActivity.this, RippleActivity.class)); break; case R.id.action_4: startActivity(new Intent(MainActivity.this, ShapeActivity.class)); break; case R.id.action_5: startActivity(new Intent(MainActivity.this, XmlActivity.class)); break; } return super.onOptionsItemSelected(item); }}
开发者
canyinghao:
License
Copyright 2016 canyinghaoLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
发表评论
最新留言
关注你微信了!
[***.104.42.241]2025年04月11日 18时15分41秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
selenium 的介绍和爬取 jd数据
2021-05-08
python-selenium优化方案
2021-05-08
服务器 centos 系统漏洞快速修复简易方法
2021-05-08
【分享-一键在线抠图】在线免费去除图片背景
2021-05-08
图片预览自适应固定宽高div
2021-05-08
layui表格checkbox选择全选样式及功能
2021-05-08
mxsrvs支持thinkphp3.2伪静态
2021-05-08
mui HTML5 plus 下载文件
2021-05-08
环信SDK 踩坑记webIM篇(一)
2021-05-08
短信验证码倒计时代码
2021-05-08
【LeetCode】归并排序(python版)
2021-05-08
通信基础知识
2021-05-08
DSP开发板准备
2021-05-08
测试基本
2021-05-08
5.redo undo
2021-05-08
《JVM的内存》
2021-05-08
c++中istringstream及ostringstream超详细说明
2021-05-08
c++中ifstream及ofstream超详细说明
2021-05-08
c++中endl操作符以及它的兄弟们
2021-05-08
c++中explicit和mutable关键字探究
2021-05-08