본문 바로가기
MOBILE/Android

안드로이드 원하는 뷰 좌우로 흔들리게 애니메이션 설정하는 방법

by 지구 2018. 8. 3.

android 에서 내가 원하는 뷰(TextView, EditView..등등) 좌우로 흔들리게끔 애니메이션 설정하는 방법.



1. res 에 anim 이란 폴더를 생성하여 cycle_3.xml 과 shake.xml 을 추가해준다. ( 보니까 anim 폴더에 안넣으면 아예 빨간 줄 뜨고 안먹더라. )

2. cycle_3.xml 구성

1
2
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
    android:cycles="3" />
cs

3. shake.xml 구성 ( 0.5초 동안 10번 만큼 3번 흔들라는 뜻으로, 각각 알맞게 수정하시면 됩니다 )

1
2
3
4
5
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0" android:toXDelta="10" android:duration="500"
    android:interpolator="@anim/cycle_3" />
 
<!-- 0.5초 동안 X10 만큼 3번 흔들어라 -->
cs

4. Activity / Fragment 에서 실제 사용

1
2
3
4
//틀렸을 시 텍스트 좌우로 흔들어주기
Animation shake = AnimationUtils.loadAnimation(getContext(), R.anim.shake);
shakeText = (TextView)findViewById(R.id.dialog_text);
shakeText.startAnimation(shake);
cs



참고 : http://iw90.tistory.com/192

반응형

댓글