如何访问anim文件夹的xml文件?

时间:2019-10-25 06:11:26

标签: android animation

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

  

应用程序出现“错误:找不到符号变量myanimation”   运行。

这是我的代码

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

2 个答案:

答案 0 :(得分:0)

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

myanimation.xml文件中也不要忘记添加所有nessasary标签。

例如,它应如下所示:

<?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>

如果仍然出现相同的错误,请执行以下操作:

File -> Invalidate Caches / Restart在Android Studio上

答案 1 :(得分:0)

`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>

这段代码对我有用。