找不到 xml 文件动画的符号
Cannot find symbol of xml file animation
我需要帮助。它说:
错误:找不到符号 fruitImage.setBackgroundResource(R.drawable.myfruits);
^
符号:变量 myfruits
位置:class 可绘制
--------------------这是代码-------------------- ---
myfruits.xml (located at drawable)
<?xmlversion="1.0"encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/img_grapes" android:duration="200"/>
<item android:drawable="@drawable/img_lemon" android:duration="200"/>
<item android:drawable="@drawable/img_orange" android:duration="200"/>
<item android:drawable="@drawable/img_pear" android:duration="200"/>
<item android:drawable="@drawable/img_strawberry" android:duration="200"/>
</animation-list>
----------------MainActivity-----------------
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView fruitImage = (ImageView) findViewById(R.id.imgFruit);
fruitImage.setBackgroundResource(R.drawable.myfruits);
fruitAnimation = (AnimationDrawable) fruitImage.getBackground();
}
这里是解释。
https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable
在您的代码中,您必须更改 myfruits.xml。
<animation-list android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/img_grapes" android:duration="200"/>
<item android:drawable="@drawable/img_lemon" android:duration="200"/>
<item android:drawable="@drawable/img_orange" android:duration="200"/>
<item android:drawable="@drawable/img_pear" android:duration="200"/>
<item android:drawable="@drawable/img_strawberry" android:duration="200"/>
</animation-list>
-----主要activity---
ImageView fruitImage = (ImageView) findViewById(R.id.imgFruit);
fruitImage.setBackgroundResource(R.drawable.myfruits);
AnimationDrawable fruitAnimation = (AnimationDrawable) fruitImage.getBackground();
fruitAnimation.start();
我需要帮助。它说: 错误:找不到符号 fruitImage.setBackgroundResource(R.drawable.myfruits); ^ 符号:变量 myfruits 位置:class 可绘制
--------------------这是代码-------------------- ---
myfruits.xml (located at drawable)
<?xmlversion="1.0"encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/img_grapes" android:duration="200"/>
<item android:drawable="@drawable/img_lemon" android:duration="200"/>
<item android:drawable="@drawable/img_orange" android:duration="200"/>
<item android:drawable="@drawable/img_pear" android:duration="200"/>
<item android:drawable="@drawable/img_strawberry" android:duration="200"/>
</animation-list>
----------------MainActivity-----------------
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView fruitImage = (ImageView) findViewById(R.id.imgFruit);
fruitImage.setBackgroundResource(R.drawable.myfruits);
fruitAnimation = (AnimationDrawable) fruitImage.getBackground();
}
这里是解释。
https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable
在您的代码中,您必须更改 myfruits.xml。
<animation-list android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/img_grapes" android:duration="200"/>
<item android:drawable="@drawable/img_lemon" android:duration="200"/>
<item android:drawable="@drawable/img_orange" android:duration="200"/>
<item android:drawable="@drawable/img_pear" android:duration="200"/>
<item android:drawable="@drawable/img_strawberry" android:duration="200"/>
</animation-list>
-----主要activity---
ImageView fruitImage = (ImageView) findViewById(R.id.imgFruit);
fruitImage.setBackgroundResource(R.drawable.myfruits);
AnimationDrawable fruitAnimation = (AnimationDrawable) fruitImage.getBackground();
fruitAnimation.start();