我一直在尝试在Android小部件中设置动画文字。具体来说,我希望文本淡入淡出。
我知道这是可能的,因为大多数Android手机附带的Genie新闻和天气小部件都可以。但是,我无法看到如何使用动画师或文本切换器完成此操作(两者似乎都不受支持)。
我假设这不是使用警报完成的,因为这似乎对动画来说是完全矫枉过正。
有谁知道这是怎么做的?
答案 0 :(得分:2)
您可以使用ViewSwitcher或TextSwitcher
<TextSwitcher
android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inAnimation="@android:anim/fade_in"
android:outAnimation="@android:anim/fade_out" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="World" />
</TextSwitcher>
如果你在textSwitcher上调用setText,它将淡出当前文本并淡入新文本。
您也可以以编程方式为任何View对象启动动画。
Animation fadeIn = AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_in);
textView.startAnimation(fadeIn);
答案 1 :(得分:1)
您可以使用Alpha动画,在xml文件中定义或以编程方式... 以下是有关动画的文档: http://developer.android.com/guide/topics/resources/animation-resource.html#alpha-element
您希望动画何时开始?