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

作者: 小怪兽打葫芦娃 | 来源:发表于2017-01-14 19:24 被阅读1855次

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

    效果图

    使用步骤

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

    allprojects {
        repositories {
            maven { url "https://jitpack.io" }
        }
    }
    

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

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

    3.布局文件中使用

    <Button
        android:id="@+id/btnStart"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Start"/>
    
    <lib.homhomlib.view2.DivergeView
        android:id="@+id/divergeView"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_width="130dp"
        android:layout_height="300dp"/>
    <ImageView
        android:id="@+id/iv_start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/ic_praise_sm6"/>
    

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

    private DivergeView mDivergeView;
    private Button mBtnStart;
    private ImageView mImageView;
    private ArrayList<Bitmap> 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);
        }
    }
    

    欢迎关注微信公众号

    相关文章

      网友评论

      • 想不到名字5588:为什么用在listview中 只有第一页的动画是正常的,下滑后,其他页的动画就不出现了。平台android 7.1,,在android 4.4平台上不存在这个问题
      • 随TT风: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isRecycled()' on a null object reference

      本文标题:Github最火开源项目-仿美拍直播的点赞动画

      本文链接:https://www.haomeiwen.com/subject/iyaebttx.html