如何访问动画文件夹的 xml 文件?



在制作动画时,我在这里创建了anim文件夹,并在该文件夹中创建了一个文件myanimation.xml。现在,我得到一个错误

"错误:在应用程序时找不到符号变量myanimation"跑

这里是我的代码

Animation aniSlide = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.myanimation);

可能您在错误的目录中创建了anim文件夹,将其移动到res

同样在myanimation.xml文件中,不要忘记添加所有nessaary标签。

例如,它应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true">
<scale
android:duration="150"
android:fillAfter="true"
android:fromXScale="1"
android:fromYScale="1"
android:startOffset="0"
android:toXScale="1.05"
android:toYScale="1.05"/>
<scale
android:duration="150"
android:fillAfter="true"
android:fromXScale="1.05"
android:fromYScale="1.05"
android:startOffset="300"
android:toXScale="1"
android:toYScale="1"/>
</set>

如果你仍然得到相同的错误,那么做:

Android Studio 上的File -> Invalidate Caches / Restart

`TextView txt = (TextView) findViewById(R.id.animText);
ScaleAnimation animation = new ScaleAnimation(0f, 3.0f, 0f, 1.5f, 
Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
animation.setDuration( 1000 );
animation.setFillAfter( true );
txt.startAnimation(animation);`
animation.xml,apply this to view
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#FFCF3C"/>
</shape>

这个代码对我有效。

最新更新