안드로이드 뷰에 애니메이션 주기 예제 , 글자흐르는 애니메이션
MainActivity.java
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | public class MainActivity extends AppCompatActivity { Animation flowAnim; TextView textView1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //애니메이션 flowAnim = AnimationUtils.loadAnimation(this, R.anim.flow); //UI textView1 = (TextView)findViewById(R.id.textView1); } //버튼 public void onButton1Clicked(View v){ //애니메이션 객체에 리스너 설정 flowAnim.setAnimationListener(new FlowAnimationListener()); flowAnim.setRepeatCount(2); //뷰에 애니메이션 설정정 textView1.startAnimation(flowAnim); } //애니메이션 리스너너 private final class FlowAnimationListener implements Animation.AnimationListener { //애니메이션 종료되었을때 @Override public void onAnimationEnd(Animation animation) { Toast.makeText(getApplicationContext(), "애니메이션 종료됨", Toast.LENGTH_SHORT).show(); } @Override public void onAnimationRepeat(Animation animation) { Log.d("ddd", "Animation Repeat"); } //애니메이션 시작했을때 @Override public void onAnimationStart(Animation animation) { Log.d("ddd", "Animation Start"); } } } | cs |
activity_main.xml
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 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:text="흐르는 글자 구현하기..." android:textColor="#00f" android:textSize="30dp" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <LinearLayout android:orientation="horizontal" android:paddingTop="10dp" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/startButton" android:text="시작 " android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onButton1Clicked" /> </LinearLayout> </LinearLayout> | cs |
anim폴더 > flow.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <!--위치이동을 위한 애니메이션 액션 정의--> <!--오른쪽에서 왼쪽으로 6초동안 이동 * 3회반복 --> <translate android:fromXDelta="100%p" android:toXDelta="0%p" android:duration="6000" android:repeatCount="3" /> <!--투명도 변경을 위한 애니메이션 액션 정의--> <!--투명도 0.1 -> 1.0 으로 6초동안 변경 * 3회반복--> <alpha android:fromAlpha="0.1" android:toAlpha="1" android:duration="6000" android:repeatCount="3" /> </set> | cs |
결과
'IT > - 프로그래밍' 카테고리의 다른 글
안드로이드 사용가능한 카메라앱 존재유무 확인 (0) | 2016.08.16 |
---|---|
안드로이드 사이드메뉴(페이지 슬라이딩) 구현 예제 (6) | 2016.08.15 |
안드로이드 프레그먼트(Fragment) 예제2 (0) | 2016.08.15 |
안드로이드 프레그먼트(Fragment) 예제 (0) | 2016.08.15 |
안드로이드 CPU Core 개수 구하기 (0) | 2016.08.13 |