栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

Android实现水波纹扩散效果的实例代码

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android实现水波纹扩散效果的实例代码

本文讲述了Android实现水波纹扩散效果的实例代码。分享给大家供大家参考,具体如下:

项目地址下载

1.效果图:

2.使用方法:

在xml里使用RippleImageView自定义控件:

xmlns:app="http://schemas.android.com/apk/res-auto"


在Activity中的使用:

rippleImageView=(RippleImageView)findViewById(R.id.rippleImageView);
//开始动画
rippleImageView.startWaveAnimation();
//停止动画
rippleImageView.stopWaveAnimation();

3.如何将自定义控件引入到项目:

拷贝自定义控件RippleImageView


public class RippleImageView extends RelativeLayout {
 private static final int SHOW_SPACING_TIME=700;
 private static final int MSG_WAVE2_ANIMATION = 1;
 private static final int MSG_WAVE3_ANIMATION = 2;
 private static final int IMAMGEVIEW_SIZE = 80;
 
 private static final int SIZE =3 ;
 
 private int show_spacing_time=SHOW_SPACING_TIME;
 
 private AnimationSet [] mAnimationSet=new AnimationSet[SIZE];
 
 private ImageView [] imgs=new ImageView[SIZE];
 
 private ImageView img_bg;
 
 private float imageViewWidth=IMAMGEVIEW_SIZE;
 private float imageViewHeigth=IMAMGEVIEW_SIZE;
 private Handler mHandler = new Handler() {
 @Override
 public void handleMessage(Message msg) {
 switch (msg.what) {
 case MSG_WAVE2_ANIMATION:
  imgs[MSG_WAVE2_ANIMATION].startAnimation(mAnimationSet[MSG_WAVE2_ANIMATION]);
  break;
 case MSG_WAVE3_ANIMATION:
  imgs[MSG_WAVE2_ANIMATION].startAnimation(mAnimationSet[MSG_WAVE3_ANIMATION]);
  break;
 }
 }
 };
 public RippleImageView(Context context) {
 super(context);
 initView(context);
 }
 public RippleImageView(Context context, AttributeSet attrs) {
 super(context, attrs);
 getAttributeSet(context,attrs);
 initView(context);
 }
 
 private void getAttributeSet(Context context, AttributeSet attrs) {
 TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.custume_ripple_imageview);
 show_spacing_time = typedArray.getInt(R.styleable.custume_ripple_imageview_show_spacing_time, SHOW_SPACING_TIME);
 imageViewWidth = typedArray.getDimension(R.styleable.custume_ripple_imageview_imageViewWidth, IMAMGEVIEW_SIZE);
 imageViewHeigth = typedArray.getDimension(R.styleable.custume_ripple_imageview_imageViewHeigth, IMAMGEVIEW_SIZE);
 Log.d("TAG","show_spacing_time="+show_spacing_time+"mm imageViewWidth="+imageViewWidth+"px imageViewHeigth="+imageViewHeigth+"px");
 typedArray.recycle();
 }
 private void initView(Context context) {
 setLayout(context);
 for (int i = 0; i 

拷贝自定义属性到arrts下


 
 
 

拷贝默认图片

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/156146.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号