补间动画

1.res下创建anim包

(1).透明度渐变:

(2).缩放渐变:

(3).位移渐变:
 
(4).旋转渐变:

(5).组合渐变:


    
    
    
    

2.Activity中:

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button b_animAlpha;
    private Button b_animScale;
    private Button b_animTran;
    private Button b_animRotate;
    private Button b_animSet;
    private ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        b_animAlpha = (Button) findViewById(R.id.b_animAlpha);
        b_animScale = (Button) findViewById(R.id.b_animScale);
        b_animTran = (Button) findViewById(R.id.b_animTran);
        b_animRotate = (Button) findViewById(R.id.b_animRotate);
        b_animSet = (Button) findViewById(R.id.b_animSet);
        iv = (ImageView) findViewById(R.id.iv);


        b_animAlpha.setOnClickListener(this);
        b_animScale.setOnClickListener(this);
        b_animTran.setOnClickListener(this);
        b_animRotate.setOnClickListener(this);
        b_animSet.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.b_animAlpha:
                Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim_alpha);
                iv.startAnimation(animation);
                animation.cancel();
                break;
            case R.id.b_animScale:
                Animation animScale = AnimationUtils.loadAnimation(this, R.anim.anim_scale);
                iv.startAnimation(animScale);
                animScale.cancel();
                break;
            case R.id.b_animTran:
                Animation animTran = AnimationUtils.loadAnimation(this, R.anim.anim_tran);
                iv.startAnimation(animTran);
                animTran.cancel();
                break;
            case R.id.b_animRotate:
                Animation animRotate = AnimationUtils.loadAnimation(this, R.anim.anim_rotate);
                iv.startAnimation(animRotate);
                animRotate.cancel();
                break;
            case R.id.b_animSet:
                Animation animSet = AnimationUtils.loadAnimation(this, R.anim.anim_set);
                animSet.setDuration(3000);
                iv.startAnimation(animSet);
                animSet.cancel();
                break;
        }
    }
}

你可能感兴趣的:(补间动画)