반응형
<shake_animation.xml>
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration = "500"
android:fromDegrees = "-10"
android:pivotX = "30%"
android:pivotY="30%"
android:repeatCount = "1"
android:repeatMode = "reverse"
android:toDegrees="10"
/>
<!--
duration: 지속기간
-->
<MainActivity>
package com.example.animation;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
//버튼클릭시 animation 실행
public void btnMethod(View view){
shakeAnimation();
}
//shakeAnimation method
private void shakeAnimation(){
Animation shake = AnimationUtils.loadAnimation(MainActivity.this,R.anim.shake_animation);
final CardView cardView = findViewById(R.id.cardView);
cardView.startAnimation(shake);
//animation listener
shake.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
cardView.setCardBackgroundColor(Color.RED); // 애니메이션 동작시 칼라변경
}
@Override
public void onAnimationEnd(Animation animation) {
cardView.setCardBackgroundColor(Color.BLUE);
//애니메이션 동작 끝날때 칼라 설정 ㄱㄱ
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});//listener finish
}//
}
'open coding' 카테고리의 다른 글
oepn coding. preferences 소규모 데이터 저장 기본 코딩 (0) | 2020.12.17 |
---|---|
앱 출시 오류 This App Bundle contains Java/Kotlin code, which might be obfuscated. 아티팩트 유형 은 난독 화 될 수 있는 자바 Kotlin 코드를 포함 합니다. 해결방법. (0) | 2020.12.06 |
open coding. 안드로이드 스튜디오 화면회전시 data유지 /화면고정/ (0) | 2020.11.29 |
open coding . 안드로이드 스튜디오 앱에 광고달기. (0) | 2020.11.27 |
open coding. 이미지 리소스 res>drawable> image.xml 만들기 (0) | 2020.11.26 |