Smooth text change in android animation

前端 未结 7 2019
刺人心
刺人心 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:09

    You can use TranslateAnimation

    An animation that controls the position of an object.

        btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                 TranslateAnimation animObj= new TranslateAnimation(0,tv.getWidth(), 0, 0);
                 animObj.setDuration(2000);
                 tv.startAnimation(animObj);
                 tv.setText(String.valueOf(Integer.valueOf((String) tv.getText()) + 1));
                }
            });
    

    You can check below links for demo case

    1. Android Animation Example
    2. Android Working with XML Animations

提交回复
热议问题