重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

如何使用Android实现水波纹扩散效果

这篇文章给大家分享的是有关如何使用Android实现水波纹扩散效果的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

创新互联是网站建设专家,致力于互联网品牌建设与网络营销,专业领域包括成都网站设计、网站建设、外贸网站建设、电商网站制作开发、微信平台小程序开发、微信营销、系统平台开发,与其他网站设计及系统开发公司不同,我们的整合解决方案结合了恒基网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,且不断评估并优化我们的方案,为客户提供全方位的互联网品牌整合方案!

具体如下:

项目地址下载

1.效果图:

如何使用Android实现水波纹扩散效果

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

/**
 * Description :
 * Author : liujun
 * Email : liujin2son@163.com
 */
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);
 }
 /**
 * 获取xml属性
 * @param context
 * @param attrs
 */
 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下


 
 
 

拷贝默认图片

感谢各位的阅读!关于“如何使用Android实现水波纹扩散效果”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!


分享标题:如何使用Android实现水波纹扩散效果
网站路径:http://cqcxhl.cn/article/gccige.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP