반응형
-blinking animation 깜빡거리는 애니메이션
-public AlphaAnimation (float fromAlpha, float toAlpha)
-listener
-Animation Android Developer 사이트 참고
package com.www.fadeanimation;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.graphics.Color;
import android.os.Bundle;
import android.view.VerifiedInputEvent;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
public class MainActivity extends AppCompatActivity {
//fade animation : visible -> invisible로 설정
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void btnMethod(View view){
fadeView();
}
private void fadeView(){
AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f,0.0f); //visible -> invisible
alphaAnimation.setDuration(350); //milliseoconds
alphaAnimation.setRepeatCount(1);
alphaAnimation.setRepeatMode(Animation.REVERSE);
final CardView cardView = findViewById(R.id.cardView);
cardView.startAnimation(alphaAnimation); //set말고 start!!!해야 실행되더라.
//listener 색깔변경
alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
cardView.setCardBackgroundColor(Color.GREEN); //시작 칼라
}
@Override
public void onAnimationEnd(Animation animation) {
cardView.setCardBackgroundColor(Color.WHITE); //끝나는 칼라
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}//finish
}