The project needs to achieve the effect of likes. Find a solution online:
http://www.jianshu.com/p/03fdcfd3ae9c
Initial use Some are okay, but a violent test found that it is very stuck and not very easy to use. And like such a troublesome animation, it is indeed necessary to use SurfaceView to achieve. So I searched for information, but didn’t find one that could be used directly. Finally, do it yourself. First look at the renderings:
When you tap the screen, a random like icon floats from the bottom of the screen.
Two core things in the demo:
1. Basic use of SurfaceView;
2. Sine wave parameter setting;
Look at the comments directly in the code
package com.example.testandroid;import java. util.LinkedList;import java.util.Random;import android.annotation.SuppressLint;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics .Color;import android.graphics.Paint;import android.graphics.PixelFormat;import android.graphics.PorterDuff.Mode;import android.util.AttributeSet;import android.view.SurfaceHolder;import android.view.SurfaceV iew;import com.example.testandroid.PraiseView.Bubble.Coordinates;/** * Like control on the live page, using SurfaceView to draw* Similar to the normal control method, the like is only required to call addBubble(int)* @ author huamm */public class PraiseView extends SurfaceView implements SurfaceHolder.Callback {private SurfaceHolder mHolder; private AnimThread mAnimThread; // thread drawing the UI private Paint mPaint; // the brush to be used for drawing private int mWidth; // the width of the control private int mHeight; // The height of the control private Bitmap[] mDrawables; // Store the pictures that need to be displayed private int[] mDrawableResIDs; // Store the pictures that need to be displayed private final LinkedListmTempList = new LinkedList (); // Used to temporarily store private final LinkedList mBubbles = new LinkedList (); // Used to store like information private OnBubbleStateListener mOnBubbleStateListener; // Listen to start and stop like private Random mRandom = new Random(); // Used to generate random numbers public PraiseView(Context context, AttributeSet attrs) {super(context, attrs); mHolder = getHolder(); mHolder.addCallback(this); mHolder.setFormat(P ixelFormat.TRANSPARENT); mPaint = new Paint(); mDrawableResIDs = new int[] {R.drawable.praise_eight, R.drawable.praise_one, R.drawable.praise_third, R.drawable.praise_two, R.drawable.praise_five, R .drawable.praise_four, R.drawable.praise_seven, R.drawable.praise_six, }; mDrawables = new Bitmap[mDrawableResIDs.length];} @Override protected void onDraw(final Canvas canvas) {if (canvas != null) {canvas .drawColor(Color.TRANSPARENT, Mode.CLEAR); // Clear the interface mTempList.clear(); synchronized (mBubbles) {mTempList.addAll(mBubbles);} for (Bubble bubble: mTempList) {Coordinates coords = bubble.coordinates; // Set transparency if (coords.y mHeight * 0.75 && coords.y mHeight*0.75 ) {bubble.scale = 0.5f + (mHeight-coords.y)*2f/mHeight; canvas.scale(bubble.scale, bubble.scale, mWidth/2, mHeight);} else {canvas.scale(1f, 1f );} canvas.drawBitmap(bubble.bitmap, coords.x, coords.y, mPaint); // Draw the image // Set the coordinates for the next drawing coords.y = coords.y-dip2px(2); coords.x = getXbyY(bubble, coords.y); // Determine whether it is already invisible if (coords.y <-dip2px(20)) { synchronized (mBubbles) {mBubbles.remove(bubble); if (mBubbles.size() <= 0 && mOnBubbleStateListener != null) {mOnBubbleStateListener.onEnd();}}}}}} private int getXbyY(Bubble bubble, int y ) {// float startx = delta-amplifier * (float) (Math.sin(phase * 2 * // (float) Math.PI / 360.0f + 2 * Math.PI * frequency / height * x)); float startx = bubble.delta-bubble.amplifier * (float) (Math.sin(bubble.data1 + bubble.data2 * y)); return (int) startx;} public void addBubble(int count) {if (mBubbles.size () <= 0 && mOnBubbleStateListener != null) {mOnBubbleStateListener.onStart();} for (int i = 0; i It is no different from general controls, just copy it and use it
https://github.com/brian512/PraiseView Reposted from: http://blog.csdn.net/brian512/article/details/50827645