Android5.0以上的项目都会有的按钮点击特效--水波纹
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android">
- <solid android:color="@color/colorPrimary"/>
- <corners android:radius="10dp" />
- <padding android:left="20dp" android:top="20dp"
- android:right="20dp" android:bottom="20dp" />
- </shape>
-
下面是点击的效果

话说这种效果应该怎样实现呢,目前我是专门针对5.0以上系统建立一个文件夹drawable-v21,里面放置带有水波纹特效的点击效果:
写一个ripple标签,这个就是水波纹特效<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#FF9e9e9e">
<item android:drawable="@drawable/bg_nomal"/>
</ripple>- 1
- 2
- 3
- 4
- 5
color是点击水波纹的颜色,一般推荐FF9e9e9e;
如果这个点击效果需要默认的图片,就是drawable的内容了,这时color的颜色最好是drawable中颜色的加深色;对于5.0以下的版本就是设置一个相同的名字的点击效果就OK了,这样就可以在android5.0以上的按钮上添加酷炫的水波纹点击效果了
- 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.Build;
- import android.os.Handler;
- 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;
- /**
- * Created by Administrator on 2016/5/3.
- */
- 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_zoomScale, 1.03f);
- zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200);
- typedArray.recycle();
- paint = new Paint();
- paint.setAntiAlias(true);
- paint.setStyle(Paint.Style.FILL_AND_STROKE);
- paint.setColor(rippleColor);
- paint.setAlpha(rippleAlpha);
- this.setWillNotDraw(false);
- gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
- @Override
- public void onLongPress(MotionEvent event) {
- super.onLongPress(event);
- animateRipple(event);
- sendClickEvent(true);
- }
- @Override
- public boolean onSingleTapConfirmed(MotionEvent e) {
- return true;
- }
- @Override
- public boolean onSingleTapUp(MotionEvent e) {
- return true;
- }
- });
- this.setDrawingCacheEnabled(true);
- this.setClickable(true);
- }
- @Override
- public void draw(Canvas canvas) {
- super.draw(canvas);
- if (animationRunning) {
- canvas.save();
- if (rippleDuration <= timer * frameRate) {
- animationRunning = false;
- timer = 0;
- durationEmpty = -1;
- timerEmpty = 0;
- // There is problem on Android M where canvas.restore() seems to be called automatically
- // For now, don't call canvas.restore() manually on Android M (API 23)
- if(Build.VERSION.SDK_INT != 23) {
- canvas.restore();
- }
- invalidate();
- if (onCompletionListener != null) onCompletionListener.onComplete(this);
- return;
- } else
- canvasHandler.postDelayed(runnable, frameRate);
- if (timer == 0)
- canvas.save();
- canvas.drawCircle(x, y, (radiusMax * (((float) timer * frameRate) / rippleDuration)), paint);
- paint.setColor(Color.parseColor("#ffff4444"));
- if (rippleType == 1 && originBitmap != null && (((float) timer * frameRate) / rippleDuration) > 0.4f) {
- if (durationEmpty == -1)
- durationEmpty = rippleDuration - timer * frameRate;
- timerEmpty++;
- final Bitmap tmpBitmap = getCircleBitmap((int) ((radiusMax) * (((float) timerEmpty * frameRate) / (durationEmpty))));
- canvas.drawBitmap(tmpBitmap, 0, 0, paint);
- tmpBitmap.recycle();
- }
- paint.setColor(rippleColor);
- if (rippleType == 1) {
- if ((((float) timer * frameRate) / rippleDuration) > 0.6f)
- paint.setAlpha((int) (rippleAlpha - ((rippleAlpha) * (((float) timerEmpty * frameRate) / (durationEmpty)))));
- else
- paint.setAlpha(rippleAlpha);
- }
- else
- paint.setAlpha((int) (rippleAlpha - ((rippleAlpha) * (((float) timer * frameRate) / rippleDuration))));
- timer++;
- }
- }
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- super.onSizeChanged(w, h, oldw, oldh);
- WIDTH = w;
- HEIGHT = h;
- scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
- scaleAnimation.setDuration(zoomDuration);
- scaleAnimation.setRepeatMode(Animation.REVERSE);
- scaleAnimation.setRepeatCount(1);
- }
- /**
- * Launch Ripple animation for the current view with a MotionEvent
- *
- * @param event MotionEvent registered by the Ripple gesture listener
- */
- public void animateRipple(MotionEvent event) {
- createAnimation(event.getX(), event.getY());
- }
- /**
- * Launch Ripple animation for the current view centered at x and y position
- *
- * @param x Horizontal position of the ripple center
- * @param y Vertical position of the ripple center
- */
- public void animateRipple(final float x, final float y) {
- createAnimation(x, y);
- }
- /**
- * Create Ripple animation centered at x, y
- *
- * @param x Horizontal position of the ripple center
- * @param y Vertical position of the ripple center
- */
- private void createAnimation(final float x, final float y) {
- if (this.isEnabled() && !animationRunning) {
- if (hasToZoom)
- this.startAnimation(scaleAnimation);
- radiusMax = Math.max(WIDTH, HEIGHT);
- if (rippleType != 2)
- radiusMax /= 2;
- radiusMax -= ripplePadding;
- if (isCentered || rippleType == 1) {
- this.x = getMeasuredWidth() / 2;
- this.y = getMeasuredHeight() / 2;
- } else {
- this.x = x;
- this.y = y;
- }
- animationRunning = true;
- if (rippleType == 1 && originBitmap == null)
- originBitmap = getDrawingCache(true);
- invalidate();
- }
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- if (gestureDetector.onTouchEvent(event)) {
- animateRipple(event);
- sendClickEvent(false);
- }
- return super.onTouchEvent(event);
- }
- @Override
- public boolean onInterceptTouchEvent(MotionEvent event) {
- this.onTouchEvent(event);
- return super.onInterceptTouchEvent(event);
- }
- /**
- * Send a click event if parent view is a Listview instance
- *
- * @param isLongClick Is the event a long click ?
- */
- private void sendClickEvent(final Boolean isLongClick) {
- if (getParent() instanceof AdapterView) {
- final AdapterView adapterView = (AdapterView) getParent();
- final int position = adapterView.getPositionForView(this);
- final long id = adapterView.getItemIdAtPosition(position);
- if (isLongClick) {
- if (adapterView.getOnItemLongClickListener() != null)
- adapterView.getOnItemLongClickListener().onItemLongClick(adapterView, this, position, id);
- } else {
- if (adapterView.getOnItemClickListener() != null)
- adapterView.getOnItemClickListener().onItemClick(adapterView, this, position, id);
- }
- }
- }
- private Bitmap getCircleBitmap(final int radius) {
- final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(), Bitmap.Config.ARGB_8888);
- final Canvas canvas = new Canvas(output);
- final Paint paint = new Paint();
- final Rect rect = new Rect((int)(x - radius), (int)(y - radius), (int)(x + radius), (int)(y + radius));
- paint.setAntiAlias(true);
- canvas.drawARGB(0, 0, 0, 0);
- canvas.drawCircle(x, y, radius, paint);
- paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
- canvas.drawBitmap(originBitmap, rect, rect, paint);
- return output;
- }
- /**
- * Set Ripple color, default is #FFFFFF
- *
- * @param rippleColor New color resource
- */
- public void setRippleColor(int rippleColor) {
- this.rippleColor = getResources().getColor(rippleColor);
- }
- public int getRippleColor() {
- return rippleColor;
- }
- public RippleType getRippleType()
- {
- return RippleType.values()[rippleType];
- }
- /**
- * Set Ripple type, default is RippleType.SIMPLE
- *
- * @param rippleType New Ripple type for next animation
- */
- public void setRippleType(final RippleType rippleType)
- {
- this.rippleType = rippleType.ordinal();
- }
- public Boolean isCentered()
- {
- return isCentered;
- }
- /**
- * Set if ripple animation has to be centered in its parent view or not, default is False
- *
- * @param isCentered
- */
- public void setCentered(final Boolean isCentered)
- {
- this.isCentered = isCentered;
- }
- public int getRipplePadding()
- {
- return ripplePadding;
- }
- /**
- * Set Ripple padding if you want to avoid some graphic glitch
- *
- * @param ripplePadding New Ripple padding in pixel, default is 0px
- */
- public void setRipplePadding(int ripplePadding)
- {
- this.ripplePadding = ripplePadding;
- }
- public Boolean isZooming()
- {
- return hasToZoom;
- }
- /**
- * At the end of Ripple effect, the child views has to zoom
- *
- * @param hasToZoom Do the child views have to zoom ? default is False
- */
- public void setZooming(Boolean hasToZoom)
- {
- this.hasToZoom = hasToZoom;
- }
- public float getZoomScale()
- {
- return zoomScale;
- }
- /**
- * Scale of the end animation
- *
- * @param zoomScale Value of scale animation, default is 1.03f
- */
- public void setZoomScale(float zoomScale)
- {
- this.zoomScale = zoomScale;
- }
- public int getZoomDuration()
- {
- return zoomDuration;
- }
- /**
- * Duration of the ending animation in ms
- *
- * @param zoomDuration Duration, default is 200ms
- */
- public void setZoomDuration(int zoomDuration)
- {
- this.zoomDuration = zoomDuration;
- }
- public int getRippleDuration()
- {
- return rippleDuration;
- }
- /**
- * Duration of the Ripple animation in ms
- *
- * @param rippleDuration Duration, default is 400ms
- */
- public void setRippleDuration(int rippleDuration)
- {
- this.rippleDuration = rippleDuration;
- }
- public int getFrameRate()
- {
- return frameRate;
- }
- /**
- * Set framerate for Ripple animation
- *
- * @param frameRate New framerate value, default is 10
- */
- public void setFrameRate(int frameRate)
- {
- this.frameRate = frameRate;
- }
- public int getRippleAlpha()
- {
- return rippleAlpha;
- }
- /**
- * Set alpha for ripple effect color
- *
- * @param rippleAlpha Alpha value between 0 and 255, default is 90
- */
- public void setRippleAlpha(int rippleAlpha)
- {
- this.rippleAlpha = rippleAlpha;
- }
- public void setOnRippleCompleteListener(OnRippleCompleteListener listener) {
- this.onCompletionListener = listener;
- }
- /**
- * Defines a callback called at the end of the Ripple effect
- */
- public interface OnRippleCompleteListener {
- void onComplete(RippleView rippleView);
- }
- public enum RippleType {
- SIMPLE(0),
- DOUBLE(1),
- RECTANGLE(2);
- int type;
- RippleType(int type)
- {
- this.type = type;
- }
- }
- }
- 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.Build;
- import android.os.Handler;
- 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;
- /**
- * Created by Administrator on 2016/5/3.
- */
- 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_zoomScale, 1.03f);
- zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200);
- typedArray.recycle();
- paint = new Paint();
- paint.setAntiAlias(true);
- paint.setStyle(Paint.Style.FILL_AND_STROKE);
- paint.setColor(rippleColor);
- paint.setAlpha(rippleAlpha);
- this.setWillNotDraw(false);
- gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
- @Override
- public void onLongPress(MotionEvent event) {
- super.onLongPress(event);
- animateRipple(event);
- sendClickEvent(true);
- }
- @Override
- public boolean onSingleTapConfirmed(MotionEvent e) {
- return true;
- }
- @Override
- public boolean onSingleTapUp(MotionEvent e) {
- return true;
- }
- });
- this.setDrawingCacheEnabled(true);
- this.setClickable(true);
- }
- @Override
- public void draw(Canvas canvas) {
- super.draw(canvas);
- if (animationRunning) {
- canvas.save();
- if (rippleDuration <= timer * frameRate) {
- animationRunning = false;
- timer = 0;
- durationEmpty = -1;
- timerEmpty = 0;
- // There is problem on Android M where canvas.restore() seems to be called automatically
- // For now, don't call canvas.restore() manually on Android M (API 23)
- if(Build.VERSION.SDK_INT != 23) {
- canvas.restore();
- }
- invalidate();
- if (onCompletionListener != null) onCompletionListener.onComplete(this);
- return;
- } else
- canvasHandler.postDelayed(runnable, frameRate);
- if (timer == 0)
- canvas.save();
- canvas.drawCircle(x, y, (radiusMax * (((float) timer * frameRate) / rippleDuration)), paint);
- paint.setColor(Color.parseColor("#ffff4444"));
- if (rippleType == 1 && originBitmap != null && (((float) timer * frameRate) / rippleDuration) > 0.4f) {
- if (durationEmpty == -1)
- durationEmpty = rippleDuration - timer * frameRate;
- timerEmpty++;
- final Bitmap tmpBitmap = getCircleBitmap((int) ((radiusMax) * (((float) timerEmpty * frameRate) / (durationEmpty))));
- canvas.drawBitmap(tmpBitmap, 0, 0, paint);
- tmpBitmap.recycle();
- }
- paint.setColor(rippleColor);
- if (rippleType == 1) {
- if ((((float) timer * frameRate) / rippleDuration) > 0.6f)
- paint.setAlpha((int) (rippleAlpha - ((rippleAlpha) * (((float) timerEmpty * frameRate) / (durationEmpty)))));
- else
- paint.setAlpha(rippleAlpha);
- }
- else
- paint.setAlpha((int) (rippleAlpha - ((rippleAlpha) * (((float) timer * frameRate) / rippleDuration))));
- timer++;
- }
- }
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- super.onSizeChanged(w, h, oldw, oldh);
- WIDTH = w;
- HEIGHT = h;
- scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
- scaleAnimation.setDuration(zoomDuration);
- scaleAnimation.setRepeatMode(Animation.REVERSE);
- scaleAnimation.setRepeatCount(1);
- }
- /**
- * Launch Ripple animation for the current view with a MotionEvent
- *
- * @param event MotionEvent registered by the Ripple gesture listener
- */
- public void animateRipple(MotionEvent event) {
- createAnimation(event.getX(), event.getY());
- }
- /**
- * Launch Ripple animation for the current view centered at x and y position
- *
- * @param x Horizontal position of the ripple center
- * @param y Vertical position of the ripple center
- */
- public void animateRipple(final float x, final float y) {
- createAnimation(x, y);
- }
- /**
- * Create Ripple animation centered at x, y
- *
- * @param x Horizontal position of the ripple center
- * @param y Vertical position of the ripple center
- */
- private void createAnimation(final float x, final float y) {
- if (this.isEnabled() && !animationRunning) {
- if (hasToZoom)
- this.startAnimation(scaleAnimation);
- radiusMax = Math.max(WIDTH, HEIGHT);
- if (rippleType != 2)
- radiusMax /= 2;
- radiusMax -= ripplePadding;
- if (isCentered || rippleType == 1) {
- this.x = getMeasuredWidth() / 2;
- this.y = getMeasuredHeight() / 2;
- } else {
- this.x = x;
- this.y = y;
- }
- animationRunning = true;
- if (rippleType == 1 && originBitmap == null)
- originBitmap = getDrawingCache(true);
- invalidate();
- }
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- if (gestureDetector.onTouchEvent(event)) {
- animateRipple(event);
- sendClickEvent(false);
- }
- return super.onTouchEvent(event);
- }
- @Override
- public boolean onInterceptTouchEvent(MotionEvent event) {
- this.onTouchEvent(event);
- return super.onInterceptTouchEvent(event);
- }
- /**
- * Send a click event if parent view is a Listview instance
- *
- * @param isLongClick Is the event a long click ?
- */
- private void sendClickEvent(final Boolean isLongClick) {
- if (getParent() instanceof AdapterView) {
- final AdapterView adapterView = (AdapterView) getParent();
- final int position = adapterView.getPositionForView(this);
- final long id = adapterView.getItemIdAtPosition(position);
- if (isLongClick) {
- if (adapterView.getOnItemLongClickListener() != null)
- adapterView.getOnItemLongClickListener().onItemLongClick(adapterView, this, position, id);
- } else {
- if (adapterView.getOnItemClickListener() != null)
- adapterView.getOnItemClickListener().onItemClick(adapterView, this, position, id);
- }
- }
- }
- private Bitmap getCircleBitmap(final int radius) {
- final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(), Bitmap.Config.ARGB_8888);
- final Canvas canvas = new Canvas(output);
- final Paint paint = new Paint();
- final Rect rect = new Rect((int)(x - radius), (int)(y - radius), (int)(x + radius), (int)(y + radius));
- paint.setAntiAlias(true);
- canvas.drawARGB(0, 0, 0, 0);
- canvas.drawCircle(x, y, radius, paint);
- paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
- canvas.drawBitmap(originBitmap, rect, rect, paint);
- return output;
- }
- /**
- * Set Ripple color, default is #FFFFFF
- *
- * @param rippleColor New color resource
- */
- public void setRippleColor(int rippleColor) {
- this.rippleColor = getResources().getColor(rippleColor);
- }
- public int getRippleColor() {
- return rippleColor;
- }
- public RippleType getRippleType()
- {
- return RippleType.values()[rippleType];
- }
- /**
- * Set Ripple type, default is RippleType.SIMPLE
- *
- * @param rippleType New Ripple type for next animation
- */
- public void setRippleType(final RippleType rippleType)
- {
- this.rippleType = rippleType.ordinal();
- }
- public Boolean isCentered()
- {
- return isCentered;
- }
- /**
- * Set if ripple animation has to be centered in its parent view or not, default is False
- *
- * @param isCentered
- */
- public void setCentered(final Boolean isCentered)
- {
- this.isCentered = isCentered;
- }
- public int getRipplePadding()
- {
- return ripplePadding;
- }
- /**
- * Set Ripple padding if you want to avoid some graphic glitch
- *
- * @param ripplePadding New Ripple padding in pixel, default is 0px
- */
- public void setRipplePadding(int ripplePadding)
- {
- this.ripplePadding = ripplePadding;
- }
- public Boolean isZooming()
- {
- return hasToZoom;
- }
- /**
- * At the end of Ripple effect, the child views has to zoom
- *
- * @param hasToZoom Do the child views have to zoom ? default is False
- */
- public void setZooming(Boolean hasToZoom)
- {
- this.hasToZoom = hasToZoom;
- }
- public float getZoomScale()
- {
- return zoomScale;
- }
- /**
- * Scale of the end animation
- *
- * @param zoomScale Value of scale animation, default is 1.03f
- */
- public void setZoomScale(float zoomScale)
- {
- this.zoomScale = zoomScale;
- }
- public int getZoomDuration()
- {
- return zoomDuration;
- }
- /**
- * Duration of the ending animation in ms
- *
- * @param zoomDuration Duration, default is 200ms
- */
- public void setZoomDuration(int zoomDuration)
- {
- this.zoomDuration = zoomDuration;
- }
- public int getRippleDuration()
- {
- return rippleDuration;
- }
- /**
- * Duration of the Ripple animation in ms
- *
- * @param rippleDuration Duration, default is 400ms
- */
- public void setRippleDuration(int rippleDuration)
- {
- this.rippleDuration = rippleDuration;
- }
- public int getFrameRate()
- {
- return frameRate;
- }
- /**
- * Set framerate for Ripple animation
- *
- * @param frameRate New framerate value, default is 10
- */
- public void setFrameRate(int frameRate)
- {
- this.frameRate = frameRate;
- }
- public int getRippleAlpha()
- {
- return rippleAlpha;
- }
- /**
- * Set alpha for ripple effect color
- *
- * @param rippleAlpha Alpha value between 0 and 255, default is 90
- */
- public void setRippleAlpha(int rippleAlpha)
- {
- this.rippleAlpha = rippleAlpha;
- }
- public void setOnRippleCompleteListener(OnRippleCompleteListener listener) {
- this.onCompletionListener = listener;
- }
- /**
- * Defines a callback called at the end of the Ripple effect
- */
- public interface OnRippleCompleteListener {
- void onComplete(RippleView rippleView);
- }
- public enum RippleType {
- SIMPLE(0),
- DOUBLE(1),
- RECTANGLE(2);
- int type;
- RippleType(int type)
- {
- this.type = type;
- }
- }
- }
Android5.0以上的项目都会有的按钮点击特效--水波纹的更多相关文章
- Web前端-按钮点击效果(水波纹)
这种效果可以由元素内嵌套canves实现,也可以由css3实现. Canves实现 网上摘了一份canves实现的代码,略微去掉了些重复定义的样式并且给出js注释,代码如下 第一种方法: html骨架 ...
- 【数据售卖平台】—— Vue2.0入门学习项目爬坑
前言:这个项目是我从零学习Vue2.0时用于练习基础知识的入门项目,包含了Vue2.0几乎所有项目都会用到的基础功能,是新手用来练手的好项目,这里温故知新对功能点做一个总结.github地址:http ...
- Android自定义组件系列【14】——Android5.0按钮波纹效果实现
今天任老师发表了一篇关于Android5.0中按钮按下的波纹效果实现<Android L中水波纹点击效果的实现>,出于好奇我下载了源代码看了一下效果,正好手边有一个Nexus手机,我结合实 ...
- Android5.0新特性之——按钮点击效果动画(涟漪效果)
Android5.0 Material Design设计的动画效果 RippleDrawable涟漪效果 涟漪效果是Android5.0以后的新特性.为了兼容性,建议新建drawable-v21文件夹 ...
- Android5.0(Lollipop) BLE蓝牙4.0+浅析code(二)
作者:Bgwan链接:https://zhuanlan.zhihu.com/p/23347612来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. Android5.0(L ...
- Vue3实战系列:Vue3.0 + Vant3.0 搭建种子项目
最近在用 Vue3 写一个开源的商城项目,开源后让大家也可以用现成的 Vue3 大型商城项目源码来练练手,目前处于开发阶段,过程中用到了 Vant3.0,于是就整理了这篇文章来讲一下如何使用 Vue3 ...
- android5.0联系人 sort_key改成phonebook_label
项目中用到了联系人根据字母排序,在android4.0手机上是可以的,但是在android4.4以上的手机排序是乱的,一般字母排序都是根据sort_key这个拼音进行排序,而android5.0这个字 ...
- 一个Activity掌握Android5.0新控件 (转)
原文地址:http://blog.csdn.net/lavor_zl/article/details/51279386 谷歌在推出Android5.0的同时推出了一些新控件,Android5.0中最常 ...
- 友情提醒:欲开发android5.0以上应用,请全部更新开发工具至最新
周末帮人完成一个项目,android5.0以上版本,谁知道被开发工具折腾的死去活来.我的开发环境是adt-bundle-windows-x86-20140702.zip版本,也是目前能找到的adt-b ...
随机推荐
- 940B Our Tanya is Crying Out Loud
传送门 题目大意 给你n,k,A,B四个数,x=n,有两种操作: 1.将x-1,需支付A个金币 2.将x÷k,需支付B个金币,当且仅当k能整除x时可进行此操作 问将x修改为1至少要花几个金币 分析 模 ...
- 【echarts3】--1 简单入门
echarts3 相信大家都了解吧,是百度研发的 ECharts 特性介绍 ECharts,一个纯 Javascript 的图表库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(IE8 ...
- 写好Java代码的30条经验总结(转)
成为一个优秀的Java程序员,有着良好的代码编写习惯是必不可少的.下面就让我们来看看代码编写的30条建议吧. (1) 类名首字母应该大写.字段.方法以及对象(句柄)的首字母应小写.对于所有标识符,其中 ...
- C/C++语言简介之语言特点
一.基本特性 1.高级语言:它是把高级语言的基本结构和语句与低级语言的实用性结合起来的工作单元. 2.结构式语言:结构式语言的显著特点是代码及数据的分隔化,即程序的各个部分除了必要的信息交 ...
- PHP安全、Sql防注入安全汇总
利用Mysqli和PDO 产生原因 主要就是一些数据没有经过严格的验证,然后直接拼接 SQL 去查询.导致漏洞产生,比如: $id = $_GET['id']; $sql = "SELECT ...
- hihoCoder 1044 : 状态压缩·一 状压dp
思路:状态压缩,dp(i, j)表示考虑前i个数且[i-m+1, i]的选择情况为j.如果要选择当前这个数并且,数位1的个数不超过q,则dp[i+1][nex] = max(dp[i+1][nex], ...
- uva 116 单向TSP
这题的状态很明显. 转移方程就是 d(i,j)=min(d(i+1,j+1),d(i,j+1),d(i-1,j+1)) //注意边界 我用了一个next数组方便打印结果,但是一直编译错误,原来是不能用 ...
- 历届试题 剪格子 IDA*
思路:限制当前能剪下的最大格子数,保证能得到最少数目.IDA*的典型运用. AC代码 #include <cstdio> #include <cmath> #include & ...
- Spring / Hibernate 应用性能调优
来源:ImportNew - 陈晓舜 对大部分典型的Spring/Hibernate企业应用来说,应用的性能大部分由持久层的性能决定. 这篇文章会重温一下怎么去确认我们的应用是否是”数据库依赖(dat ...
- 电脑中dll文件丢失怎么恢复?
DLL文件是Windows系统中的动态链接文件,我们在运行程序时都必须链接到dll文件,如果缺少了则无法正常运行,相信大家都会遇到dll文件缺失的情况,那么电脑中dll文件丢失怎么恢复?下面装机之家分 ...