Smooth text change in android animation

前端 未结 7 2020
刺人心
刺人心 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条回答
  •  Happy的楠姐
    2020-12-11 01:04

    The easiest way to do this is:

    btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                            ViewGroup parent=(ViewGroup) tv.getParent();                 //get parent of the TextView
                            parent.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);            //enable animations
                            tv.setText(String.valueOf(Integer.valueOf((String) tv.getText()) + 1));                   //change the text
            }
        });
    

    Now, your text should change slowly and nicely

提交回复
热议问题