设为首页 加入收藏

TOP

Android 实现RippleEffect水波纹效果(一)
2015-11-10 13:45:28 来源: 作者: 【 】 浏览:2
Tags:Android 实现 RippleEffect 波纹 效果

Android 实现RippleEffect水波纹效果


1.RippleEffect核心实现类


package com.example.RippleEffect;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.os.Handler;
import android.support.annotation.ColorRes;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.AdapterView;
import android.widget.RelativeLayout;
?
?
/**
?* RippleView custom layout
?*
?* Custom Layout that allows to use Ripple UI pattern above API 21
?*/
public class RippleView extends RelativeLayout {
?
? ? private int WIDTH;
? ? private int HEIGHT;
? ? private int frameRate = 10;
? ? private int rippleDuration = 400;
? ? private int rippleAlpha = 90;
? ? private Handler canvasHandler;
? ? private float radiusMax = 0;
? ? private boolean animationRunning = false;
? ? private int timer = 0;
? ? private int timerEmpty = 0;
? ? private int durationEmpty = -1;
? ? private float x = -1;
? ? private float y = -1;
? ? private int zoomDuration;
? ? private float zoomScale;
? ? private ScaleAnimation scaleAnimation;
? ? private Boolean hasToZoom;
? ? private Boolean isCentered;
? ? private Integer rippleType;
? ? private Paint paint;
? ? private Bitmap originBitmap;
? ? private int rippleColor;
? ? private int ripplePadding;
? ? private GestureDetector gestureDetector;
? ? private final Runnable runnable = new Runnable() {
? ? ? ? @Override
? ? ? ? public void run() {
? ? ? ? ? ? invalidate();
? ? ? ? }
? ? };
?
? ? private OnRippleCompleteListener onCompletionListener;
?
? ? public RippleView(Context context) {
? ? ? ? super(context);
? ? }
?
? ? public RippleView(Context context, AttributeSet attrs) {
? ? ? ? super(context, attrs);
? ? ? ? init(context, attrs);
? ? }
?
? ? public RippleView(Context context, AttributeSet attrs, int defStyle) {
? ? ? ? super(context, attrs, defStyle);
? ? ? ? init(context, attrs);
? ? }
?
? ? /**
? ? * Method that initializes all fields and sets listeners
? ? *
? ? * @param context Context used to create this view
? ? * @param attrs Attribute used to initialize fields
? ? */
? ? private void init(final Context context, final AttributeSet attrs) {
? ? ? ? if (isInEditMode())
? ? ? ? ? ? return;
?
? ? ? ? final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView);
? ? ? ? rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color, getResources().getColor(R.color.rippelColor));
? ? ? ? rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0);
? ? ? ? hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false);
? ? ? ? isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false);
? ? ? ? rippleDuration = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, rippleDuration);
? ? ? ? frameRate = typedArray.getInteger(R.styleable.RippleView_rv_framerate, frameRate);
? ? ? ? rippleAlpha = typedArray.getInteger(R.styleable.RippleView_rv_alpha, rippleAlpha);
? ? ? ? ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0);
? ? ? ? canvasHandler = new Handler();
? ? ? ? zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomS

首页 上一页 1 2 3 4 5 6 下一页 尾页 1/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux网络编程--信号阻塞与屏蔽(.. 下一篇Android 使用shape制作drawable素..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: