Smooth text change in android animation

前端 未结 7 2029
刺人心
刺人心 2020-12-11 00:29

I want to add animation in android text view so that when a text changes it should change smoothly and slowly. Like, fade in or fade out when the text changes. Is it possibl

7条回答
  •  一个人的身影
    2020-12-11 01:03

    use TextSwitcher

    
        
        
    
    

    Array of Strings to show in TextSwitcher

    String textToShow[] = {"Main HeadLine", "Your Message", "New In Technology"};
    

    You have to set animation

    mSwitcher.setInAnimation(context, android.R.anim.slide_in_left);
    mSwitcher.setOutAnimation(context, android.R.anim.slide_out_right);
    

    Animation is triggered by calling method setText(CharSequence text)

    // When clicked on Button TextSwitcher will switch between texts
    btnNext.setOnClickListener(new View.OnClickListener() {
        public void onClick (View v) {
    
           currentIndex++;
           // If index reaches maximum reset it
           if (currentIndex == messageCount) {
              currentIndex = 0;
           }
    
           mSwitcher.setText(textToShow[currentIndex]);
    }):
    

    If you want to set text without animation, call method setCurrentText(CharSequence text).

提交回复
热议问题