我目前使用一种主要的解决方法,每次更改 TextView 上的文本时都会切换两个 Activity 。我正在使用此代码:
Weeklytext.this.overridePendingTransition(
R.anim.slide_in_left,
R.anim.slide_out_right
);
是否可以在一个 Activity 中做到这一点?有两个内容完全相同的 Activity 只是为了让我可以使用动画,这有点烦人;)
谢谢! 如果您不明白我的问题,请询问!
最佳答案
您可以使用 TextSwitcher在 TextView 中更改文本时有动画。
TextSwitcher 只是一种特殊的 ViewSwitcher ,因此,它允许您提供两个 View ,在它们之间进行动画处理。当您调用 setText() 时,它会更新下一个 TextView 的文本,然后将其动画化到屏幕上,并将当前的动画化。然后将旧的 TextView 指定为“下一个”TextView,并重复该过程。
您可以使用 setFactory(...) 指定 View 或者只是简单地使用 addView(...) 添加两个 TextViews .
// 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");
关于android - 更改 TextView 时的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7573870/