Github最火开源项目-仿美拍直播的点赞动画

项目地址:https://github.com/open-android/Android-DivergeView2.

效果图

Github最火开源项目-仿美拍直播的点赞动画_第1张图片

使用步骤

1. 在project的build.gradle添加如下代码(如下图)

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}
Github最火开源项目-仿美拍直播的点赞动画_第2张图片

2. 在Module的build.gradle添加依赖

compile 'com.github.open-android:Android-DivergeView2:0.1.0'

3.布局文件中使用

4.复制如下代码到java类中

private DivergeView mDivergeView;
private Button mBtnStart;
private ImageView mImageView;
private ArrayList mList;
private int mIndex = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mBtnStart = (Button)findViewById(R.id.btnStart);
    mImageView = (ImageView)findViewById(R.id.iv_start);
    mList = new ArrayList<>();
    mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.ic_praise_sm1, null)).getBitmap());
    mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.ic_praise_sm2,null)).getBitmap());
    mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.ic_praise_sm3,null)).getBitmap());
    mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.ic_praise_sm4,null)).getBitmap());
    mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.ic_praise_sm5,null)).getBitmap());
    mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.ic_praise_sm6, null)).getBitmap());
    mBtnStart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(mIndex == 5){
                mIndex = 0 ;
            }
            mDivergeView.startDiverges(mIndex);
            mIndex++;
        }
    });
    mDivergeView = (DivergeView) findViewById(R.id.divergeView);
    mDivergeView.post(new Runnable() {
        @Override
        public void run() {
            mDivergeView.setEndPoint(new PointF(mDivergeView.getMeasuredWidth()/2,0));
            mDivergeView.setDivergeViewProvider(new Provider());
        }
    });
}

@Override
protected void onDestroy() {
    super.onDestroy();
    if(mList != null){
        mList.clear();
        mList = null;
    }

}

class Provider implements DivergeView.DivergeViewProvider{

    @Override
    public Bitmap getBitmap(Object obj) {
        return mList == null ? null : mList.get((int)obj);
    }
}

欢迎关注微信公众号

Github最火开源项目-仿美拍直播的点赞动画_第3张图片

你可能感兴趣的:(Github最火开源项目-仿美拍直播的点赞动画)