Android 仿支付宝9.0芝麻信用分效果

本文介绍了如何在Android中模仿支付宝9.0版本的芝麻信用分数展示动画。通过计算五边形的角度和坐标,使用ValueAnimator动态更新绿色区域,实现了根据后台数据动态刷新的效果。提供了一个下载链接供读者查看和学习代码。
摘要由CSDN通过智能技术生成

最近看到IOS支付宝9.0芝麻信用分效果,感觉很酷,恰好这段时间学习安卓动画,就先拿它小试牛刀,如有雷同,纯属巧合

先看支付宝芝麻信用分图:


抱歉没有做GIF图,大家可以去支付宝看看效果,当打开该界面时,默认展现的灰色正五边形,绿色区域也是与平行于外五边形,不过是半径小于外无边行而已,然后一秒内结合后台数据,计算用户的各项指标,动态刷新绿色区域

现在来看看我们的效果图:


抱歉没有相关图片,只能找相关图片替代了,GIF效果也不是很好,后边会给大家提供下载链接提供下载,大家可以运行看看效果


说说思路:

1.首先是五边形的计算方式,大家都知道,五边形每两条边形成的角度是108度,则中心点形成的角度是72度,问为什么,大家自行百度五边形

2.怎么确定各个点,中心点不用说,View的width 于height的一半,半径则为各个width与height较小的(为了适配个屏幕,我们取小的那个)减去最大图片的宽高

3.怎么绘制五边形,我们现在有了半径,有了中心点,则用path可以确定各个点的坐标了吧,绿色那块,完全可以以半径的百分比确定,默认我们取半径的一半

4.绿色区域效果,可以根据当前的百分比与默认的百分比,这里边用到了ValueAnimator,则可以拿到当前的变化的值,然后动态刷新View即可

5.1秒之后执行效果,则可以开启一个线程,一秒之后执行Value Animator


好了,不说了,上代码:

package wh.sesamecreditview.view;

import android.animation.ValueAnimator;
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.Path;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Looper;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

import java.math.BigDecimal;
import java.util.ArrayList;

import wh.sesamecreditview.R;
import wh.sesamecreditview.util.DisplayUtil;

/**
 * Created by Administrator on 2015/8/5.
 */
public class SesameCreditView extends View {
    private Point mCenterPoint = new Point();
    private int mViewWidth;
    private int mViewHeight;
    private int mCenterX;
    private int mCenterY;
    private int mRadius;
    private Paint mDefaultPaint = new Paint();
    private Paint mLineDefaultPaint = new Paint();
    private Paint mVisivlePaint = new Paint();
    private Paint mTextPaint = new Paint();
    private Paint mBitmapPaint = new Paint();
    private double mIdentityValue;
    private double mCreditValue;
    private double mCreditHistoryValue;
    private double mPepoleRelativeValue;
    private double mActionFavoriteValue;
    private String mDefaultText = "未知";
    private Rect mTextRect = new Rect();
    private float mDefaultRatio = 0.5f;
    private int mPicAndViewSpacing;
    private ArrayList<Region> mPicAreas = new ArrayList<Region>();
    priv
自定义View之仿支付宝芝麻信用仪表盘效果,喜欢的话,请给个star,谢谢.使用添加项目依赖Add it in your root build.gradle at the end of repositories: allprojects {         repositories { ... maven { url "https://jitpack.io" }         }     } Add the dependency     dependencies {             compile 'com.github.HotBitmapGG:CreditSesameRingView:V1.0.2' }新版芝麻信用使用     // The gradient color can define your own private final int[] mColors = new int[]{             0xFFFF80AB,             0xFFFF4081,             0xFFFF5177,             0xFFFF7997              }; // Set up the need to score mLayout = (RelativeLayout) view.findViewById(R.id.layout);       mButton = (Button) view.findViewById(R.id.btn);       newCreditSesameView = (NewCreditSesameView) view.findViewById(R.id.sesame_view);       mLayout.setBackgroundColor(mColors[0]);       mButton.setOnClickListener(new View.OnClickListener()       { @Override public void onClick(View view)            {                newCreditSesameView.setSesameValues(639);                startColorChangeAnim();            }       }); // The background color gradient animation Simply illustrates the effect Can customize according to your need public void startColorChangeAnim()      { ObjectAnimator animator = ObjectAnimator.ofInt(mLayout, "backgroundColor", mColors);          animator.setDuration(3000);          animator.setEvaluator(new ArgbEvaluator());          animator.start();      }旧版芝麻信用使用      // Set up the need to score oldCreditSesameView = (OldCreditSesameView) view.findViewById(R.id.sesame_view);       mButton = (Button) view.findViewById(R.id.btn);       mButton.setOnClickListener(new View.OnClickListener()       { @Override public void onClick(View view)           {               oldCreditSesameView.setSesameValues(639);           }       });
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值