我目前使用一个主要的解决方法,每次更改 TextView 上的文本时都会切换两个活动。我正在使用这段代码:
Weeklytext.this.overridePendingTransition(
R.anim.slide_in_left,
R.anim.slide_out_right
);
是否可以在一个 Activity 中执行此操作?有两个具有完全相同内容的 Activity 只是为了使用动画,这有点烦人;)
谢谢!
如果您不明白我的问题,请询问!
您可以使用文本切换器 http://developer.android.com/reference/android/widget/TextSwitcher.html更改 TextView 中的文本时有动画。
TextSwitcher 只是一种特殊的视图切换器 http://developer.android.com/reference/android/widget/ViewSwitcher.html,因此,它允许您提供两个视图,并在两个视图之间进行动画处理。当您调用 setText() 时,它会更新下一个 TextView 的文本,然后将该文本动画显示到屏幕中,并将当前文本动画显示出来。然后旧的 TextView 被指定为“下一个”TextView 并重复该过程。
您可以使用指定视图设置工厂(...) http://developer.android.com/reference/android/widget/ViewSwitcher.html#setFactory%28android.widget.ViewSwitcher.ViewFactory%29或者只是简单地添加两个 TextViews 到它添加视图(...) http://developer.android.com/reference/android/widget/TextSwitcher.html#addView%28android.view.View,%20int,%20android.view.ViewGroup.LayoutParams%29.
// 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");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)