2011-09-27 5 views
34

저는 현재 주요 해결 방법을 사용하고 TextView에서 텍스트를 변경할 때마다 두 가지 작업을 전환했습니다. 이 코드를 사용하고 있습니다 :텍스트 뷰를 변경할 때의 애니메이션

Weeklytext.this.overridePendingTransition( 
        R.anim.slide_in_left, 
        R.anim.slide_out_right 
      ); 

하나의 활동에서이 작업을 수행 할 수 있습니까? 애니메이션을 사용할 수 있도록 똑같은 내용의 두 가지 활동을 성가 시게하는 것입니다.)

고마워요! 내 질문을 이해할 수 없는지 물어보십시오!

답변

66

TextView에서 텍스트를 변경할 때 TextSwitcher을 사용하여 애니메이션을 만들 수 있습니다.

TextSwitcher는 특별한 종류의 ViewSwitcher 일 뿐이므로 사이에 애니메이션을 적용 할 두 개의보기를 제공 할 수 있습니다. setText()를 호출하면 다음 TextView의 텍스트를 업데이트 한 다음 해당 텍스트를 화면에 애니메이션으로 표시하고 현재 텍스트를 애니메이션으로 출력합니다. 이전 TextView는 '다음'TextView로 지정되고 프로세스가 반복됩니다.

setFactory(...)을 사용하여 뷰를 지정하거나 addView(...)으로 두 개의 TextView를 추가하기 만하면됩니다.

// get a TextSwitcher view; instantiate in code or resolve from a layout/XML 
TextSwitcher textSwitcher = new TextSwitcher(context); 

// specify the in/out animations you wish to use 
textSwitcher.setInAnimation(context, R.anim.slide_in_left); 
textSwitcher.setOutAnimation(context, R.anim.slide_out_right); 

// provide two TextViews for the TextSwitcher to use 
// you can apply styles to these Views before adding 
textSwitcher.addView(new TextView(context)); 
textSwitcher.addView(new TextView(context)); 

// you are now ready to use the TextSwitcher 
// it will animate between calls to setText 
textSwitcher.setText("hello"); 
... 
textSwitcher.setText("goodbye"); 
+0

나는 그것이 내가 필요로하는 정확하게 같게 들린다!! 나는 그것을 사용하는 방법을 알아 내야 만합니다. – Lorof

+1

@Lorenz 당신을 도울 수있는 몇 가지 코드를 추가했습니다 : – antonyt

+0

좋은 예 : http://www.learn-android-easily.com/2013/06/android-textswitcher.html –

관련 문제