MainActivity.java
package com.llw.animationdemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ImageView ivLogo, ivAlphaLogo, ivTranslateLogo, ivScaleLogo;
private Button btnShow, btnHide, btnAlphaShow, btnAlphaHide, btnTranslateShow,
btnTranslateHide, btnScaleShow, btnScaleHide;
private AlphaAnimation alphaAniShow, alphaAniHide;
private TranslateAnimation translateAniShow, translateAniHide;
private Animation bigAnimation, smallAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
//初始化控件
private void initView() {
ivLogo = (ImageView) findViewById(R.id.iv_logo);
ivAlphaLogo = (ImageView) findViewById(R.id.iv_alpha_logo);
ivTranslateLogo = (ImageView) findViewById(R.id.iv_translate_logo);
ivScaleLogo = (ImageView) findViewById(R.id.iv_scale_logo);
btnShow = (Button) findViewById(R.id.btn_show);
btnHide = (Button) findViewById(R.id.btn_hide);
btnAlphaShow = (Button) findViewById(R.id.btn_alpha_show);
btnAlphaHide = (Button) findViewById(R.id.btn_alpha_hide);
btnTranslateShow = (Button) findViewById(R.id.btn_translate_show);
btnTranslateHide = (Button) findViewById(R.id.btn_translate_hide);
btnScaleShow = (Button) findViewById(R.id.btn_scale_show);
btnScaleHide = (Button) findViewById(R.id.btn_scale_hide);
btnShow.setOnClickListener(this);