动画改变TextView的时候 [英] Animation when changing textview

查看:169
本文介绍了动画改变TextView的时候的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用的一个主要的解决办法,有两个活动,每个I更改一个TextView的文字时切换。我用这code:

I currently use a major workaround and have two activities switching each time I change the text on a TextView. I am using this code:

Weeklytext.this.overridePendingTransition( 
                    R.anim.slide_in_left, 
                    R.anim.slide_out_right
            );

是否有可能做到这一点在一个活动?这是一种恼人的有两个活动具有完全相同的内容只是让我可以使用动画;)

Is it possible to do this in one Activity? It's kind of annoying having two Activities with the exact same content just so that I can use animations ;)

谢谢! 请问,如果你不明白我的问题!

Thanks! Please ask if you don't understand my Question!

推荐答案

您可以使用 TextSwitcher 改变一个TextView的文本时有动画。

You can use a TextSwitcher to have animations when changing the text in a TextView.

一个TextSwitcher仅仅是一种特殊的 ViewSwitcher 的,正因为如此,它可以让你提供从中之间设置动画两项意见。当你调用的setText(),它更新下一个TextView的文本,然后动画,一个到屏幕,而目前一个出来。旧的TextView,然后指定为下一个的TextView并重复上述过程。

A TextSwitcher is just a special kind of ViewSwitcher, and as such, it lets you provide two Views from which to animate between. When you call setText(), it updates the text of the next TextView and then animates that one into the screen, and the current one out. The old TextView is then designated as the 'next' TextView and the process repeats.

您可以使用指定的视图<一href="http://developer.android.com/reference/android/widget/ViewSwitcher.html#setFactory%28android.widget.ViewSwitcher.ViewFactory%29">setFactory(...)或者只是简单地添加两个TextViews将其与<一个href="http://developer.android.com/reference/android/widget/TextSwitcher.html#addView%28android.view.View,%20int,%20android.view.ViewGroup.LayoutParams%29">addView(...).

You can specify the Views using setFactory(...) or just simply add two TextViews to it with addView(...).

// 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");

这篇关于动画改变TextView的时候的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆