Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 |
Tags
- 코테
- flutter getx
- 오블완
- c++ 코테
- 파이썬
- DP
- 티스토리챌린지
- 파이썬 코테
- Python
- Laravel
- vue
- til
- 알고리즘
- Flutter
- react
- 라라벨
- 뷰
- ML
- 99클럽
- 플러터
- 코딩테스트 준비
- 코딩테스트준비
- 코테 파이썬
- C++
- 개발자취업
- 개발자 취업
- 항해99
- 백준
- 코딩테스트
- 안드로이드
Archives
- Today
- Total
잡다로그
애니메이션 - 둘째 마당 8장 chapter01 본문
공부 중 기억해야 할 부분을 기록하기 위한 글입니다. 자세한 내용은 직접 책을 보시거나 강의를 들으시길 추천합니다 :)
![]() |
|
08-1 애니메이션 사용하기
트윈 애니메이션(Tweened Animation): 이동, 확대, 축소, 회전과 같이 일정한 패턴으로 움직이는 애니메이션을 구현할 때 사용된다.
1. 애니메이션이 어떻게 동작하는지를 XML로 정의한다.
애니메이션 액션 정보는 /app/res 폴더 안에 있어야 인식된다.
// 대상을 두 배로 확대하는 스케일 액션. scale.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="2500"
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="2.0"
android:toYScale="2.0"
/>
</set>
두 개의 애니메이션이 연속으로 수행되도록 하나로 묶어두는 방법
<set> 태그를 사용해 여러 애니메이션 액션을 포함시킨다.
//scale2.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="2500"
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="2.0"
android:toYScale="2.0"
/>
<scale
android:startOffset="2500"
android:duration="2500"
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="0.5"
android:toYScale="0.5"
/>
</set>
2. XML을 로딩하여 애니메이션 객체로 만듦 - XML 정보는 자바 소스에서 애니메이션 객체로 로딩한 후 뷰 객체의 startAnimation() 메서드를 사용해서 애니메이션을 동작하게 한다.
3. 뷰에 애니메이션을 적용하여 동작시킴
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.scale);
v.startAnimation(anim);
}
});
}
}'App > Android' 카테고리의 다른 글
| Android 소셜 로그인 관련 개념들(용어) - Keystroe, OAuth, SHA-1, Token (0) | 2024.02.14 |
|---|---|
| [실습/예제] 리싸이클러뷰(RecyclerView) 만들기 - 둘째 마당 7장 chpater04 (0) | 2021.02.17 |
| 기존 뷰 상속받아 새로운 뷰 만들기 - 둘째 마당 7장 chapter02~03 (0) | 2021.02.13 |
| [해결] 클래스 오류 - 빨간 줄 없애기 (0) | 2021.02.12 |
| 나인패치(Nine Patch) - 둘째 마당 7장 chapter01 (0) | 2021.02.10 |
Comments
