lottie動畫實戰(仿汽車之家,BOSS直聘APP底部Tab切換動畫)


GitHub地址:https://github.com/kongpf8848/Animation

效果如下:

  

 主要是自定義View繼承LottieAnimationView並實現Checkable接口,代碼如下:

import android.content.Context;
import android.util.AttributeSet;
import android.widget.Checkable;

import com.airbnb.lottie.LottieAnimationView;

public class AnimationRadioView extends LottieAnimationView implements Checkable {

    private boolean checked;

    public AnimationRadioView(Context context) {
        this(context, null);
    }

    public AnimationRadioView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public AnimationRadioView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    public boolean isChecked() {
        return this.checked;
    }

    @Override
    public void setChecked(boolean checked) {

        try {
            if (this.checked != checked) {
                this.checked = checked;
                if (isAnimating()) {
                    cancelAnimation();
                }
                if (checked) {
                    if (getSpeed() < 0.0F) {
                        reverseAnimationSpeed();
                    }
                    playAnimation();
                } else {
                    if (getSpeed() > 0.0F) {
                        reverseAnimationSpeed();
                    }
                    playAnimation();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void toggle() {
        setChecked(!this.checked);
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM