Android 补间动画快速闪烁且不起作用
我正在尝试使 TextView 缩放并淡出。我的 TextView 位于一个布局文件内,该文件包含在我的 Activity 的布局中
<include android:id="@+id/hud" layout="@layout/hud" android:layout_alignParentBottom="true"/>
,现在,我可以从 Java 代码中应用缩放动画,如下所示:
TextView multiplier = (TextView)findViewById(R.id.hudMultiplier);
ScaleAnimation s = new ScaleAnimation(1.0f, 3.0f, 1.0f,3.0f);
s.setDuration(5000);
multiplier.startAnimation(s);
它工作得很好,但我想要来自xml 文件。所以我制作了这个文件:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://shemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
android:pivotX="50%"
android:pivotY="100%"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="10.0"
android:toYScale="10.0"
android:duration="5000"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="2000"
android:startOffset="2000">
</alpha>
</set>
我尝试使用以下代码应用动画:
TextView multiplier = (TextView)findViewById(R.id.hudMultiplier);
AnimationSet an = (AnimationSet) AnimationUtils.loadAnimation(getApplicationContext(), R.anim.multiplier);
multiplier.startAnimation(an);
现在发生的情况是 TextView 闪烁了几分之一秒,但实际上什么也没发生。
我尝试过:
- 删除 alpha 动画 - 没有更改
- 删除起始偏移 - 没有更改
- 使用 android 文档中的一个更改动画 - 没有更改
- 将 AnimationSet 更改为动画 - 没有更改
- 将 getApplicationContext() 更改为此,MyActivity.this - 否将
- getApplicationContext() 更改为 null - 终止应用程序
我缺少什么?
该项目针对 Android 1.6,我正在 2.3 模拟器中进行测试。
I am trying to make a TextView scale and fade out. My TextView is inside a layout file that is included into my activity's layout with
<include android:id="@+id/hud" layout="@layout/hud" android:layout_alignParentBottom="true"/>
Now, I can apply a scale animation from within the Java code like this:
TextView multiplier = (TextView)findViewById(R.id.hudMultiplier);
ScaleAnimation s = new ScaleAnimation(1.0f, 3.0f, 1.0f,3.0f);
s.setDuration(5000);
multiplier.startAnimation(s);
And it works nicely, but I want that animation (and a bunch of others) from an xml file. So I made this file:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://shemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
android:pivotX="50%"
android:pivotY="100%"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="10.0"
android:toYScale="10.0"
android:duration="5000"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="2000"
android:startOffset="2000">
</alpha>
</set>
I am trying to apply the animation with this code:
TextView multiplier = (TextView)findViewById(R.id.hudMultiplier);
AnimationSet an = (AnimationSet) AnimationUtils.loadAnimation(getApplicationContext(), R.anim.multiplier);
multiplier.startAnimation(an);
What happens now is that the TextView blinks for a fraction of a second and nothing actually happens.
I've tried:
- removing the alpha animation - no change
- removing the start offset - no change
- change the animation with one from the android documentation - no change
- change AnimationSet to Animation - no change
- change getApplicationContext() to this, MyActivity.this - no change
- change getApplicationContext() to null - kills the application
What am I missing?
The project is targeted at Android 1.6 and I'm testing in a 2.3 emulator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无论如何,这似乎对我来说很重要!
将 shemas 更改为 Set 元素中的模式。
This seems to make a difference, for me anyway!
Change shemas to schemas in the Set element.
试试这个:
try this: