天天看点

Android view之点赞容易,取消不易

点击打开链接

可以去dribbble上看看原生效果。

代码下载

好的app在功能完善的基础上,从细节上吸引用户。虽然点赞这个功能点已经很普遍了,但是千篇一律的生硬效果让这么神圣的操作显得很黯淡(扯淡了,不就是赞赞赞么...),当然也有非常炫酷的,忍不住多点几次赞的效果。比如twitter的点赞。就不码字扯淡了,上图上源码

Android view之点赞容易,取消不易

like.png

Android view之点赞容易,取消不易

shot.gif

使用Path画爱心

Path path = new Path();
        path.moveTo((float) ( * realWidth) + rectFlove.left, (float) ( * realHeight) + rectFlove.top);
        path.cubicTo((float) ( * realWidth) + rectFlove.left, (float) ( * realHeight + rectFlove.top),
                (float) ( * realWidth) + rectFlove.left, (float) ( * realHeight) + rectFlove.top,
                (float) ( * realWidth) + rectFlove.left, (float) (realHeight *  + rectFlove.top));
//        path.moveTo( (float) (0.5 * realWidth) + rectFlove.left, (float) (realHeight * 0.8 + rectFlove.top));
        path.cubicTo((float) (realWidth +  * realWidth) + rectFlove.left, (float) ( * realHeight) + rectFlove.top,
                (float) (realWidth -  * realWidth) + rectFlove.left, (float) ( * realHeight) + rectFlove.top,
                (float) ( * realWidth) + rectFlove.left, (float) ( * realHeight) + rectFlove.top);
        path.close();
           

取消时候爱心出现裂痕然后分成两半分别向左右倾斜,使用 canvas

rotate来旋转达到倾斜效果

mBitmapBrokenLeftLove = Bitmap.createBitmap(getMeasuredWidth(), (int) lastY, Bitmap.Config.ARGB_8888);
        canvas = new Canvas(mBitmapBrokenLeftLove);
        canvas.rotate(*mBrokenAngle * mAnimatedBrokenValue, lastX, lastY);

        Path path = new Path();
        path.moveTo((float) ( * realWidth) + rectFlove.left, (float) ( * realHeight) + rectFlove.top);
        path.cubicTo((float) ( * realWidth) + rectFlove.left, (float) ( * realHeight + rectFlove.top),
                (float) ( * realWidth) + rectFlove.left, (float) ( * realHeight) + rectFlove.top,
                (float) ( * realWidth) + rectFlove.left, (float) (realHeight *  + rectFlove.top));
        path.lineTo(thirdX, thirdY);
        path.lineTo(secondX, secondY);
        path.close();
        canvas.drawPath(path, mPaintLike);
           

Gradle

Usage xml

<com.ldoublem.thumbUplib.ThumbUpView
            android:id="@+id/tpv"
            android:layout_width="50dp"
            android:layout_height="50dp"
            app:cracksColor="#33475f"
            app:edgeColor="#9d55b8"
            app:fillColor="#ea8010"
            app:unlikeType="1"
            />
           
mThumbUpView.setCracksColor(Color.rgb(, , ));
        mThumbUpView.setFillColor(Color.rgb(, , ));
        mThumbUpView.setEdgeColor(Color.rgb(, , ));
        mThumbUpView.setOnThumbUp(new ThumbUpView.OnThumbUp() {
            @Override
            public void like(boolean like) {
            }
        });
        mThumbUpView.Like();
        mThumbUpView.UnLike();
           

如果觉得还可以,给颗小星星^^

代码下载