woong's

Android EditText Shake Animation 사용하기 본문

Develop/Android

Android EditText Shake Animation 사용하기

dlsdnd345 2016. 2. 14. 17:10
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Android EditText Shake Animation 사용하기


안녕하세요. 개인어플을 만들다보니 EditText 관련해서 작업하다 포스트를 쓰고 있습니다 .


보통 EditText에 값이 없고 액션을 취하면 값이 없다는 Toast 메세지를 보여주곤 합니다 .

하지만 이와같이 Toast 메세지만 보여주면 EditText가 많은경우에는 어떤 EditText가 값이 없는지

눈에 확들어오지 않기 때문에 저는 Shake Animation 을 통해서 사용자에게 좀 더 자연스러운 연출을

해보고자 이렇게 사용해보고 다른분들도 이용할 수 있도록 포스트를 써보려 합니다 .







사용방법


1. amination xml 작성

 




이와같이 두개의 anim 을 만들어야 합니다 .


cycle_7 anim 이 shake anim 에서 사용 됩니다 .


cycle_7 


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

 

 

shake

 

1
2
3
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0" android:toXDelta="10" android:duration="1000"
    android:interpolator="@anim/cycle_7" />

 

​이와 같이 작성하면 1초 동안 X 10 만큼씩 7번 흔들어라 정도가 되겠습니다 . 



2. 코드 적용


1
2
3
4
5
6
7
            if(!editTitle.getText().toString().equals("")){
                board.setTitle(editTitle.getText().toString());
            }else{
                Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
                editTitle.startAnimation(shake);
                Toast.makeText(getApplicationContext(), "제목을 입력해 주세요.", Toast.LENGTH_LONG).show();
            }

 

 

 

 

​핵심코드는 위의 코드 입니다 . 

Anim 에서 만든 파일을 불러옵니다 .

불러와서 해당 EditText에 Animation 을 넣어주면 되겠습니다 .


정말 간단하면서도 사용자에게 Animation을 통해 보다 자여스러운 Validate 확인할 수 있습니다 .


Comments